Skip to content

Tag: sql

Insert datetime from C# into SQL Server database

when I try to insert datetime value into a SQL Server database I get this error: Conversion failed when converting date and/or time from character string Code: Table table has 1 datetime column called time. Edit: my table created in msSQL 2012: http://i.imgur.com/TJ3t3y7.png my real code is: Answer The actual…

What does SQL Server do with a timed out request?

Suppose that I use C# to run a long running SQL Server stored procedure (lets say 30 minutes). Further suppose that I put a 1 hour timeout period on the query in C# such that if for whatever reason this SP takes longer than expected, I don’t end up monopolizing the DB. Lastly, suppose that this stored p…

What determines the locking order for a multi-table query?

Does the SQL standard specify the locking order for a multi-table query? For example, given: Does the SQL standard guarantee a locking order or is it determined by the (implementation-specific) execution plan? Is there a way to guarantee a locking order? If there is no way to guarantee locking order, how are …

Count NULL Values from multiple columns with SQL

I have 3 columns let say A, B, and C. I need to count the NULL values in each column. For example: Should output: I’ve tried count, sum, sub-queries but nothing has worked for me yet. Any input would be appreciated! Answer

Flattening a hierarchial data set in Oracle

I have a set of data as shown below I need to flatten this data as below: And so on. I can have up to 30 parent child relationship I used the connect by and sys_connect_by_path as follows The result set is too large. There are other trees in this table and I don’t think it just looks at the

How to add value to SET field in mysql?

I have a table named user with a field of type SET named privs. The allowed values of this field are: ‘ADD’,’EDIT’,DELETE’,’ALL’. What SQL query should I execute to add let’s say value ‘EDIT’ to the field privs for a given row? But only if there is n…

Select EMP with max SAL from each DEPT

I´m having a bad time with a SQL query. I´m using oracle default tables: ‘EMP’ TABLE http://imageshack.us/photo/my-images/850/sinttuloxps.png/ AND ‘DEPT’ TABLE http://imageshack.us/photo/my-images/19/assayp.png/ I wan´t to get the employee with the highest salary in each department. I´…