March 23, 2010 at 1:28 pm
An example of data I have is as follows:
Entry_ID TimeStamp Activity_Code
670242 2010-02-15 12:15:00 P
680243 2010-02-15 15:30:00 P
692451 2010-02-15 12:45:00 P
I am trying to write a Case statement that retrieves each row individually. And, I need a unique name for each such as P_1, P_2, etc.
An example of my code is
(Case When ACTIVITY_CODE = 'P' Then CONVERT(nvarchar(5), STARTTIME, 108)Else '' End) as P1_start,
This would work if there was only one listing for the P activity code. However, there are multiple listings.
I think I need to add "AND" and something else to identify each of these separately.
Any suggestions are appreciated.
March 23, 2010 at 1:31 pm
Are you trying to turn the rows into columns? I'm not entirely clear on what end result you want here.
- Gus "GSquared", RSVP, OODA, MAP, NMVP, FAQ, SAT, SQL, DNA, RNA, UOI, IOU, AM, PM, AD, BC, BCE, USA, UN, CF, ROFL, LOL, ETC
Property of The Thread
"Nobody knows the age of the human race, but everyone agrees it's old enough to know better." - Anon
March 23, 2010 at 1:50 pm
Entry_ID TimeStamp Activity_Code
670242 2010-02-15 12:15:00 P
680243 2010-02-15 15:30:00 P
692451 2010-02-15 12:45:00 P
No, I am not trying to turn rows into columns. The End result would be to assign a unique column name based on the Activity Code - P and the order of the timestamps. Therefore, the records above would be P1_start, P2_start and P3_start. This will be coded within a Case/When statement. The entry_Ids are not specific. I cannot code it by the entry_id. Please advise
VT
March 23, 2010 at 2:52 pm
I am currently exploring the rank function. Hopefully, this will work.
VT
Viewing 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply