October 24, 2011 at 1:58 pm
I'm tring to get results that has first name and last name in a single row rather than column, any help would be appreciated.
SELECT distinct FIELD_ID,
CASE WHEN FIELD_ID = 6 THEN FIELD_VALUE ELSE '' END AS [FirstName],
CASE WHEN FIELD_ID = 7 THEN FIELD_VALUE ELSE '' END AS [LastName]
From tblTemp
Current Table:
FIELD_IDFIELD_VALUEUSER_ID
7Jones196
6Tom196
7West197
6Dave197
Desired Results:
USER_IDFirst_NameLast_Name
196TomJones
197DaveWest
thanks
October 24, 2011 at 4:43 pm
mnicholas (10/24/2011)
I'm tring to get results that has first name and last name in a single row rather than column, any help would be appreciated.SELECT distinct FIELD_ID,
CASE WHEN FIELD_ID = 6 THEN FIELD_VALUE ELSE '' END AS [FirstName],
CASE WHEN FIELD_ID = 7 THEN FIELD_VALUE ELSE '' END AS [LastName]
From tblTemp
Current Table:
FIELD_IDFIELD_VALUEUSER_ID
7Jones196
6Tom196
7West197
6Dave197
Desired Results:
USER_IDFirst_NameLast_Name
196TomJones
197DaveWest
thanks
You were almost there...
SELECT [User_ID],
MAX(CASE WHEN FIELD_ID = 6 THEN FIELD_VALUE ELSE '' END) AS [FirstName],
MAX(CASE WHEN FIELD_ID = 7 THEN FIELD_VALUE ELSE '' END) AS [LastName]
FROM tblTemp
GROUP BY [User_ID]
;
--Jeff Moden
Change is inevitable... Change for the better is not.
Viewing 2 posts - 1 through 1 (of 1 total)
You must be logged in to reply to this topic. Login to reply