Saturday, July 27, 2013

[T-SQL] how to : determine something based on several colomns value.

[T-SQL] how to : determine something based on several colomns value.


how to : determine something based on several colomns value.

Posted: 26 Jul 2013 05:05 AM PDT

I will try to explain the best I can the situation I am facingI have a table with 12 'bit columns' each of them reprensent a potential specific problematics. In the web form, user check the problematic he is facing, they are separeted in 3 sections of 4 checkbox, if he checks one checkbox in a section, the checkbox is the 2 others section gray outsobit columns 1 to 4 refers to category 1bit columns 5 to 8 refers to category 2bit columns 9 to 12 refers to category 3I need to build a query from that table to fill a reportrow 1, bit column 3 is set to true : I need to return -> Category 1row 2, bit column 5 is set to true : I need to return -> Category 2How can I manage this, with a CASE?thanks

Limit when a trigger runs

Posted: 26 Jul 2013 01:13 AM PDT

Is there any way to limit the trigger, so that it only runs when the app is a .Net SqlClient Data Provider? Or ...not to run if the app starts with SQLAgent or SQL Server Management Studio?(looking at a trace "ApplicationName" column.)Thanks

Add one MilliSecond to each row

Posted: 26 Jul 2013 03:06 AM PDT

Hello EveryoneI am trying something, that I am not sure is possible.I have a CreateDate column in a table, there are approx 5000 rows with the same date and time. This was done from the data load. I need to change the the time by adding one millisecond to each one, but incrementing by one from the previous row.So if I have a datetime like this:[code="sql"]RowID, CreateDate1, 2013-07-30 08:20:40:0102, 2013-07-30 08:20:40:0103, 2013-07-30 08:20:40:0104, 2013-07-30 08:20:40:0105, 2013-07-30 08:20:40:010[/code]I would like to add one millisecond to each, but incrementing from the previous row.[code="sql"]RowID, CreateDate1, 2013-07-30 08:20:40:0102, 2013-07-30 08:20:40:0113, 2013-07-30 08:20:40:0124, 2013-07-30 08:20:40:0135, 2013-07-30 08:20:40:014[/code]Here is some dummy code.[code="sql"]; WITH DifferentTimes( RowID, CreateDate)AS(SELECT TOP (500) n = CONVERT(INT, ROW_NUMBER() OVER (ORDER BY s1.[object_id])), '2013-07-30 08:20:40:010'FROM sys.all_objects AS s1 CROSS JOIN sys.all_objects AS s2)SELECT * FROM DifferentTimes[/code]So after that, I am not sure how I can perform an update to increment the time by each row, using the previous row.Thank You in advance for all your assistance, suggestions and commentsAndrew SQLDBA

No comments:

Post a Comment

Search This Blog