May 18, 2015 at 7:39 am
Please see attached. It comes from a table by the name 'HOS_EMPLOYEES'
I need to write a PIVOT statement that will produce the following columns:
pat_id, date_of_lvad , reg , QUERY_4723, REGISTRY
Note: reg and date_of_lvad are tied together. Means it always stays constant per Pat_id
Let me know if you need additional information.
May 18, 2015 at 7:50 am
mw112009 (5/18/2015)
Please see attached. It comes from a table by the name 'HOS_EMPLOYEES'I need to write a PIVOT statement that will produce the following columns:
pat_id, date_of_lvad , reg , QUERY_4723, REGISTRY
Note: reg and date_of_lvad are tied together. Means it always stays constant per Pat_id
Let me know if you need additional information.
How about ddl and sample data? That would make this a LOT easier. In the meantime you might take a look at the link in my signature about cross tabs.
_______________________________________________________________
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/
May 18, 2015 at 8:10 am
No HELP needed.. I figured out
Select *
FROM
(
Select Pat_ID, reg, date_of_lvad, method_found as [method_found]
FROM ABCD
)as s
PIVOT
(
COUNT(method_found)
FOR [method_found] in ( [QUERY-4301],[QUERY-4723],[REGISTRY],[REGISTRY-(NO ADM DT)] )
)AS p
May 18, 2015 at 8:11 am
mw112009 (5/18/2015)
No HELP needed.. I figured outSelect *
FROM
(
Select Pat_ID, reg, date_of_lvad, method_found as [method_found]
FROM ABCD
)as s
PIVOT
(
COUNT(method_found)
FOR [method_found] in ( [QUERY-4301],[QUERY-4723],[REGISTRY],[REGISTRY-(NO ADM DT)] )
)AS p
Glad you figured it out and thanks for sharing your solution.
_______________________________________________________________
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 4 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply