Quantcast
Channel: SQLServerCentral » SQL Server 2014 » Development - SQL Server 2014 » Latest topics
Viewing all articles
Browse latest Browse all 3145

t-sql help with grouping

$
0
0
Hello,I am hoping this is possible to do in a select but I cannot seem to get sql for it. We are running different types of tests per sample unit and logging whether it succeeded or failed. There is no limit to how many times a test will be run per unit. Here is what sample data looks like (0 - failed, 1- passed)SampleUnit TestID Passed TestDate11111 1 0 2015-09-03 00:00:01.00011111 1 0 2015-09-03 00:00:05.00011111 1 1 2015-09-03 00:00:10.00011111 1 0 2015-09-03 01:00:01.00011111 1 0 2015-09-03 02:00:05.00011111 1 1 2015-09-03 03:00:10.00011111 1 1 2015-09-03 10:00:27.00011111 2 1 2015-09-03 00:00:01.000I need to be able to group all failed tries followed by the first succeeded one together as one group. this is what I need for my output to look likeSampleUnit TestID Passed TestDate TestGroup11111 1 0 2015-09-03 00:00:01.000 111111 1 0 2015-09-03 00:00:05.000 111111 1 1 2015-09-03 00:00:10.000 111111 1 0 2015-09-03 01:00:01.000 211111 1 0 2015-09-03 02:00:05.000 211111 1 1 2015-09-03 03:00:10.000 211111 1 1 2015-09-03 10:00:27.000 311111 2 1 2015-09-03 00:00:01.000 1Any help or ideas would be greatly appreciated. SQL with sample data population is attachedthanks!

Viewing all articles
Browse latest Browse all 3145

Trending Articles