July 7, 2014 at 8:43 am
Hi,
I have the following data
UIdCOIDCLIdSID
1 109
1210
1 320
1439
2 502
2513
2529
2 533
2540
2600
2610
2620
2630
2640
2 700
2710
2720
2731
2740
I need the following result from the above data
UnIdCoIDClIdSID
1109
1219
1320
1439
2502
2515
2529
2533
2540
2600
2610
2620
2630
2640
2700
2710
2720
2731
2740
The query needs to add Sid value when the CLid =1 it should add the SID value when both CLid=0 and CLid=1
Thanks.
July 7, 2014 at 9:11 am
sql_novice_2007 (7/7/2014)
Hi,I have the following data
UIdCOIDCLIdSID
1 109
1210
1 320
1439
2 502
2513
2529
2 533
2540
2600
2610
2620
2630
2640
2 700
2710
2720
2731
2740
I need the following result from the above data
UnIdCoIDClIdSID
1109
1219
1320
1439
2502
2515
2529
2533
2540
2600
2610
2620
2630
2640
2700
2710
2720
2731
2740
The query needs to add Sid value when the CLid =1 it should add the SID value when both CLid=0 and CLid=1
Thanks.
I am guessing that what you want is the value from the "previous" row? There are a couple of issue with this. First of all you have to have something in your table to use as an order. From you sample data I think you could use Clid. However the column names are so shortened they don't have any meaning so it is hard for us to know.
Secondly, if you could post this as ddl and insert statements we can work on your problem instead of setting it up. Take a look at the first link in my signature for best practices when posting questions.
_______________________________________________________________
Need help? Help us help you.
Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.
Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.
Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/
Viewing 2 posts - 1 through 1 (of 1 total)
You must be logged in to reply to this topic. Login to reply