Tag: mysql

How to use the SQL MINUS keyword

I am building a social network using asp.net sql, but I am having a problem with using MINUS Operator on SQL. I Select all friend’s user data using following keywords Select * from [UserData] And i want to reduce following query from that query SELECT * FROM [Friendship] WHERE Friend2 = ‘” + Session[“Email”].ToString() + […]

Difference over sums in SQL

I have a table like the following: PARENTREF TRANSTYPE(BIT(1)) DUEDATE(DateTime) TOTAL 2038 0 2015-01-01 1000 2038 1 2015-03-05 500 2039 0 2015-01-01 1000 2040 0 2015-01-01 1000 2041 0 2015-01-01 1000 2040 1 2015-04-07 200 I want a SELECT query that returns SUM(TOTAL) when TRANSTYPE=1 subtracted from SUM(TOTAL) when TRANSTYPE=0 for each distinct PARENTREF. I […]

Ordering by field combined

I have this set of rules to sort my results in both MySQL & sql-server: First sort by qty – from highest to lowest Above sorted result sort again by storage, and first put 2, than values >2, than <2 Above sorted result sort once again by price – from lowest to highest I wrote […]

conversion of a nvarchar data type to a datetime data type in stored procedure

I am getting error when I pass date date for start date and end date that is string value from textbox to sql. alter procedure [dbo].[sp_insert_ProjectDetail] (@projectname varchar(max), @projectnos varchar(20), @Task_assigned varchar(max), @Startdate varchar(30), @enddate varchar(30), @status varchar(20), @analyst varchar(max), @qualitycheck varchar(max) )as declare @value as varchar(20) INSERT INTO tbl_ProjectDetails(ProjectName,ProjectNos,Task_assigned,Startdate,enddate,Analyst,Qualitycheck,flag,Status_Name)VALUES (@projectname,@projectnos,@Task_assigned,@Startdate,@enddate,@analyst,@qualitycheck,0,@status)

How to count number of rows with the same column data and display to table?

I have 2 tables, the ‘department’ and ‘document’. Table department | doc_id | dept_name | ———————————- | 1 | Information Technology| | 2 | Software Development | | 3 | Human Resource | | 4 | Accounting | | 5 | Support | Table document | doc_id | doc_name | author | description | department […]

toggle sql column on null JOIN value

So I query a table called markers where I join to a table that contains edits of those markers and select the most recent edit from the table (table name: content_edits). However, not all markers have edits (and return thus return null in the query) so I would like to default to the date which […]

PHP Fatal error: Call to a member function prepare() on a non-object in admin\includes\html\database.class.php on line 45

I tried getting the answer using other similar links to my question, but couldn’t solve. Other questions refereed to have a PHP class, and use it. In my case I already have PHP Class, and I still get the same error. I made this class as per explanation on the following link: culttt.com/2012/10/01/roll-your-own-pdo–php-class/ In my […]

Error at ps.executeQuery(sql) while using sql with timestamps

I am getting dates from JSP and casting them into timestamp DBConnection = ConnMgr.getConnection(); Timestamp timestamp1 = new java.sql.Timestamp(date1.getTime()); Timestamp timestamp2 = new java.sql.Timestamp(date2.getTime()); I have a sql statement and prepared staement as follows String sql = ” select * from images where uploadedOn>=? and uploadedOn<=?;”; ps = DBConnection.prepareStatement(sql); ps.setTimestamp(1, timestamp1); ps.setTimestamp(2, timestamp2); System.out.println(ps); This […]

delete rows not correspondent in sql tables

I find here a solution to delete row in one table not corresponding to another table with a where id condition: DELETE FROM MyTable1 WHERE id=1 AND NOT EXISTS (SELECT * FROM MyTable2 WHERE id=1) But I have about 10000 rows that Id’s in MyTable1 are not in MyTable2, and is very trying to find […]

PHP Fatal error: Call to a member function bind_param() on a non-object (PHP-MySQL PreparedStatement)

I know this has been asked several times here but I assure you i tried every suggestion but that didn’t help me. (I guess because this error is caused by a wide number of factors). Here is my code: $stmt = $conn->prepare(“INSERT INTO User (Username, Password, Email, Race) VALUES (?, ?, ?, ?)”); $stmt->bind_param(“ssss”, $Username, […]

MS SQL Server is a Microsoft SQL Database product, include sql server standard, sql server management studio, sql server express and so on.