Click here to Skip to main content
15,891,136 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,



I have a table like this :
SQL
Name	Value
Employee_RefID	BF-006205
Physical_Environment	3
TLM_DISPLAY	4
Emotional_Environment	4
Complete_Lesson_Plan	4
Use_of_Instructional_aids_technique	4
Open_ended_questioning	4
Active_listening	4
Student_talk_time	4
Creative_TLMs	3
Conduct_of_activity_based_teaching	3
Seating_arrangement	3
Effective_verbal_and_non_verbal_communication	3
Friendly_disposition_of_Teachers	4
Response_time_for_students_to_answer	4
Small_Group_Work	3
Maximizing_learning_time	4
Appropriate_TLM	3
Use_of_ICT	3
Organisation_of_hand_work	2
Appropriate_Opening	3
Suitable_Closing	3
Cooperation_of_Teacher	4
Courtesy_of_Teacher	4
Peer_assistance	4
Punctuality	3
Conduct	4
Grooming	4
Respect_for_Students_Peers	4
Respect_for_Community	3
Honesty_and_Integrity	3
Professional_dealing_with_parents	3
Helps_parents_understand_childs_needs_progress	3
Maintenance_of_records_proper_filling_of_MIS_economic_usage_of_stationery	4
Practicises_hygienic_behaviour	3
Encourages_Hygiene_behaviour_in_students	3
Uses_Computer_independently	3
Able_to_work_with_software_installed	4
Able_to_fill_up_computer_based_MIS_independently	3
Employee_RefID	BF-005196
Physical_Environment	3
TLM_DISPLAY	3
Emotional_Environment	4
Complete_Lesson_Plan	3
Use_of_Instructional_aids_technique	4
Open_ended_questioning	4
Active_listening	4
Student_talk_time	4
Creative_TLMs	3
Conduct_of_activity_based_teaching	3
Seating_arrangement	4
Effective_verbal_and_non_verbal_communication	4
Friendly_disposition_of_Teachers	4
Response_time_for_students_to_answer	3
Small_Group_Work	3
Maximizing_learning_time	4
Appropriate_TLM	3
Use_of_ICT	3
Organisation_of_hand_work	3
Appropriate_Opening	4
Suitable_Closing	4
Cooperation_of_Teacher	4
Courtesy_of_Teacher	3
Peer_assistance	4
Punctuality	4
Conduct	3
Grooming	4
Respect_for_Students_Peers	3
Respect_for_Community	4
Honesty_and_Integrity	4
Professional_dealing_with_parents	3
Helps_parents_understand_childs_needs_progress	3
Maintenance_of_records_proper_filling_of_MIS_economic_usage_of_stationery	4
Practicises_hygienic_behaviour	3
Encourages_Hygiene_behaviour_in_students	3
Uses_Computer_independently	4
Able_to_work_with_software_installed	3
Able_to_fill_up_computer_based_MIS_independently	3
Employee_RefID	BF-005194
Physical_Environment	3
TLM_DISPLAY	4
Emotional_Environment	4
Complete_Lesson_Plan	3
Use_of_Instructional_aids_technique	3
Open_ended_questioning	4
Active_listening	4
Student_talk_time	4
Creative_TLMs	4
Conduct_of_activity_based_teaching	4
Seating_arrangement	3
Effective_verbal_and_non_verbal_communication	4
Friendly_disposition_of_Teachers	4
Response_time_for_students_to_answer	4
Small_Group_Work	3
Maximizing_learning_time	4
Appropriate_TLM	3
Use_of_ICT	3
Organisation_of_hand_work	3
Appropriate_Opening	3
Suitable_Closing	3
Cooperation_of_Teacher	4
Courtesy_of_Teacher	3
Peer_assistance	4
Punctuality	3
Conduct	3
Grooming	4
Respect_for_Students_Peers	3
Respect_for_Community	3
Honesty_and_Integrity	4
Professional_dealing_with_parents	4
Helps_parents_understand_childs_needs_progress	4
Maintenance_of_records_proper_filling_of_MIS_economic_usage_of_stationery	4
Practicises_hygienic_behaviour	3
Encourages_Hygiene_behaviour_in_students	3
Uses_Computer_independently	3
Able_to_work_with_software_installed	3
Able_to_fill_up_computer_based_MIS_independently	3
Employee_RefID	BF-005913
Physical_Environment	3
TLM_DISPLAY	3
Emotional_Environment	3
Complete_Lesson_Plan	4
Use_of_Instructional_aids_technique	4
Open_ended_questioning	4
Active_listening	4
Student_talk_time	4
Creative_TLMs	3
Conduct_of_activity_based_teaching	2
Seating_arrangement	3
Effective_verbal_and_non_verbal_communication	4
Friendly_disposition_of_Teachers	2
Response_time_for_students_to_answer	3
Small_Group_Work	3
Maximizing_learning_time	3
Appropriate_TLM	4
Use_of_ICT	3
Organisation_of_hand_work	2
Appropriate_Opening	3
Suitable_Closing	3
Cooperation_of_Teacher	4
Courtesy_of_Teacher	4
Peer_assistance	3
Punctuality	4
Conduct	3
Grooming	3
Respect_for_Students_Peers	4
Respect_for_Community	4
Honesty_and_Integrity	3
Professional_dealing_with_parents	4
Helps_parents_understand_childs_needs_progress	3
Maintenance_of_records_proper_filling_of_MIS_economic_usage_of_stationery	4
Practicises_hygienic_behaviour	3
Encourages_Hygiene_behaviour_in_students	3
Uses_Computer_independently	3
Able_to_work_with_software_installed	3
Able_to_fill_up_computer_based_MIS_independently	3
Employee_RefID	BF-006038
Physical_Environment	4
TLM_DISPLAY	4
Emotional_Environment	3
Complete_Lesson_Plan	3
Use_of_Instructional_aids_technique	3
Open_ended_questioning	4
Active_listening	4
Student_talk_time	4
Creative_TLMs	4
Conduct_of_activity_based_teaching	4
Seating_arrangement	3
Effective_verbal_and_non_verbal_communication	3
Friendly_disposition_of_Teachers	3
Response_time_for_students_to_answer	4
Small_Group_Work	4
Maximizing_learning_time	4
Appropriate_TLM	3
Use_of_ICT	3
Organisation_of_hand_work	2
Appropriate_Opening	4
Suitable_Closing	3
Cooperation_of_Teacher	4
Courtesy_of_Teacher	4
Peer_assistance	4
Punctuality	3
Conduct	3
Grooming	4
Respect_for_Students_Peers	3
Respect_for_Community	3
Honesty_and_Integrity	4
Professional_dealing_with_parents	3
Helps_parents_understand_childs_needs_progress	4
Maintenance_of_records_proper_filling_of_MIS_economic_usage_of_stationery	3
Practicises_hygienic_behaviour	3
Encourages_Hygiene_behaviour_in_students	4
Uses_Computer_independently	3
Able_to_work_with_software_installed	3
Able_to_fill_up_computer_based_MIS_independently	4
Employee_RefID	BF-006039
Physical_Environment	3
TLM_DISPLAY	2
Emotional_Environment	4
Complete_Lesson_Plan	4
Use_of_Instructional_aids_technique	4
Open_ended_questioning	2
Active_listening	4
Student_talk_time	4
Creative_TLMs	2
Conduct_of_activity_based_teaching	4
Seating_arrangement	3
Effective_verbal_and_non_verbal_communication	4
Friendly_disposition_of_Teachers	3
Response_time_for_students_to_answer	3
Small_Group_Work	2
Maximizing_learning_time	2
Appropriate_TLM	4
Use_of_ICT	4
Organisation_of_hand_work	2
Appropriate_Opening	3
Suitable_Closing	3
Cooperation_of_Teacher	3
Courtesy_of_Teacher	4
Peer_assistance	4
Punctuality	4
Conduct	3
Grooming	3
Respect_for_Students_Peers	3
Respect_for_Community	4
Honesty_and_Integrity	3
Professional_dealing_with_parents	3
Helps_parents_understand_childs_needs_progress	4
Maintenance_of_records_proper_filling_of_MIS_economic_usage_of_stationery	4
Practicises_hygienic_behaviour	3
Encourages_Hygiene_behaviour_in_students	3
Uses_Computer_independently	4
Able_to_work_with_software_installed	3
Able_to_fill_up_computer_based_MIS_independently	4
I want to convert into coloumn wise like where they meet with employee_RefID a new row create and and all the rest data show into the coloumns can anybody provide me query what i have to done.

Thanks in Advance
Posted

Hi,
Check this link,
Simple query to create a Pivot.

Simple Way To Use Pivot In SQL Query[^]
 
Share this answer
 
Try this:
SQL
CREATE TABLE #tmp ([Name] VARCHAR(300),[Value] VARCHAR(300))

INSERT INTO #tmp ([Name], [Value])
SELECT 'Employee_RefID', 'BF-006205'
UNION ALL SELECT 'Physical_Environment', '3'
UNION ALL SELECT 'TLM_DISPLAY', '4'
UNION ALL SELECT 'Emotional_Environment', '4'
UNION ALL SELECT 'Complete_Lesson_Plan', '4'
UNION ALL SELECT 'Use_of_Instructional_aids_technique', '4'
UNION ALL SELECT 'Open_ended_questioning', '4'
UNION ALL SELECT 'Active_listening', '4'
UNION ALL SELECT 'Student_talk_time', '4'
UNION ALL SELECT 'Creative_TLMs', '3'
UNION ALL SELECT 'Conduct_of_activity_based_teaching', '3'
UNION ALL SELECT 'Seating_arrangement', '3'
UNION ALL SELECT 'Effective_verbal_and_non_verbal_communication', '3'
UNION ALL SELECT 'Friendly_disposition_of_Teachers', '4'
UNION ALL SELECT 'Response_time_for_students_to_answer', '4'
UNION ALL SELECT 'Small_Group_Work', '3'
UNION ALL SELECT 'Maximizing_learning_time', '4'
UNION ALL SELECT 'Appropriate_TLM', '3'
UNION ALL SELECT 'Use_of_ICT', '3'
UNION ALL SELECT 'Organisation_of_hand_work', '2'
UNION ALL SELECT 'Appropriate_Opening', '3'
UNION ALL SELECT 'Suitable_Closing', '3'
UNION ALL SELECT 'Cooperation_of_Teacher', '4'
UNION ALL SELECT 'Courtesy_of_Teacher', '4'
UNION ALL SELECT 'Peer_assistance', '4'
UNION ALL SELECT 'Punctuality', '3'
UNION ALL SELECT 'Conduct', '4'
UNION ALL SELECT 'Grooming', '4'
UNION ALL SELECT 'Respect_for_Students_Peers', '4'
UNION ALL SELECT 'Respect_for_Community', '3'
UNION ALL SELECT 'Honesty_and_Integrity', '3'
UNION ALL SELECT 'Professional_dealing_with_parents', '3'
UNION ALL SELECT 'Helps_parents_understand_childs_needs_progress', '3'
UNION ALL SELECT 'Maintenance_of_records_proper_filling_of_MIS_economic_usage_of_stationery', '4'
UNION ALL SELECT 'Practicises_hygienic_behaviour', '3'
UNION ALL SELECT 'Encourages_Hygiene_behaviour_in_students', '3'
UNION ALL SELECT 'Uses_Computer_independently', '3'
UNION ALL SELECT 'Able_to_work_with_software_installed', '4'
UNION ALL SELECT 'Able_to_fill_up_computer_based_MIS_independently', '3'
UNION ALL SELECT 'Employee_RefID', 'BF-005196'
UNION ALL SELECT 'Physical_Environment', '3'
UNION ALL SELECT 'TLM_DISPLAY', '3'
UNION ALL SELECT 'Emotional_Environment', '4'
UNION ALL SELECT 'Complete_Lesson_Plan', '3'
UNION ALL SELECT 'Use_of_Instructional_aids_technique', '4'
UNION ALL SELECT 'Open_ended_questioning', '4'
UNION ALL SELECT 'Active_listening', '4'
UNION ALL SELECT 'Student_talk_time', '4'
UNION ALL SELECT 'Creative_TLMs', '3'
UNION ALL SELECT 'Conduct_of_activity_based_teaching', '3'
UNION ALL SELECT 'Seating_arrangement', '4'
UNION ALL SELECT 'Effective_verbal_and_non_verbal_communication', '4'
UNION ALL SELECT 'Friendly_disposition_of_Teachers', '4'
UNION ALL SELECT 'Response_time_for_students_to_answer', '3'
UNION ALL SELECT 'Small_Group_Work', '3'
UNION ALL SELECT 'Maximizing_learning_time', '4'
UNION ALL SELECT 'Appropriate_TLM', '3'
UNION ALL SELECT 'Use_of_ICT', '3'
UNION ALL SELECT 'Organisation_of_hand_work', '3'
UNION ALL SELECT 'Appropriate_Opening', '4'
UNION ALL SELECT 'Suitable_Closing', '4'
UNION ALL SELECT 'Cooperation_of_Teacher', '4'
UNION ALL SELECT 'Courtesy_of_Teacher', '3'
UNION ALL SELECT 'Peer_assistance', '4'
UNION ALL SELECT 'Punctuality', '4'
UNION ALL SELECT 'Conduct', '3'
UNION ALL SELECT 'Grooming', '4'
UNION ALL SELECT 'Respect_for_Students_Peers', '3'
UNION ALL SELECT 'Respect_for_Community', '4'
UNION ALL SELECT 'Honesty_and_Integrity', '4'
UNION ALL SELECT 'Professional_dealing_with_parents', '3'
UNION ALL SELECT 'Helps_parents_understand_childs_needs_progress', '3'
UNION ALL SELECT 'Maintenance_of_records_proper_filling_of_MIS_economic_usage_of_stationery', '4'
UNION ALL SELECT 'Practicises_hygienic_behaviour', '3'
UNION ALL SELECT 'Encourages_Hygiene_behaviour_in_students', '3'
UNION ALL SELECT 'Uses_Computer_independently', '4'
UNION ALL SELECT 'Able_to_work_with_software_installed', '3'
UNION ALL SELECT 'Able_to_fill_up_computer_based_MIS_independently', '3'
UNION ALL SELECT 'Employee_RefID', 'BF-005194'
UNION ALL SELECT 'Physical_Environment', '3'
UNION ALL SELECT 'TLM_DISPLAY', '4'
UNION ALL SELECT 'Emotional_Environment', '4'
UNION ALL SELECT 'Complete_Lesson_Plan', '3'
UNION ALL SELECT 'Use_of_Instructional_aids_technique', '3'
UNION ALL SELECT 'Open_ended_questioning', '4'
UNION ALL SELECT 'Active_listening', '4'
UNION ALL SELECT 'Student_talk_time', '4'
UNION ALL SELECT 'Creative_TLMs', '4'
UNION ALL SELECT 'Conduct_of_activity_based_teaching', '4'
UNION ALL SELECT 'Seating_arrangement', '3'
UNION ALL SELECT 'Effective_verbal_and_non_verbal_communication', '4'
UNION ALL SELECT 'Friendly_disposition_of_Teachers', '4'
UNION ALL SELECT 'Response_time_for_students_to_answer', '4'
UNION ALL SELECT 'Small_Group_Work', '3'
UNION ALL SELECT 'Maximizing_learning_time', '4'
UNION ALL SELECT 'Appropriate_TLM', '3'
UNION ALL SELECT 'Use_of_ICT', '3'
UNION ALL SELECT 'Organisation_of_hand_work', '3'
UNION ALL SELECT 'Appropriate_Opening', '3'
UNION ALL SELECT 'Suitable_Closing', '3'
UNION ALL SELECT 'Cooperation_of_Teacher', '4'
UNION ALL SELECT 'Courtesy_of_Teacher', '3'
UNION ALL SELECT 'Peer_assistance', '4'
UNION ALL SELECT 'Punctuality', '3'
UNION ALL SELECT 'Conduct', '3'
UNION ALL SELECT 'Grooming', '4'
UNION ALL SELECT 'Respect_for_Students_Peers', '3'
UNION ALL SELECT 'Respect_for_Community', '3'
UNION ALL SELECT 'Honesty_and_Integrity', '4'
UNION ALL SELECT 'Professional_dealing_with_parents', '4'
UNION ALL SELECT 'Helps_parents_understand_childs_needs_progress', '4'
UNION ALL SELECT 'Maintenance_of_records_proper_filling_of_MIS_economic_usage_of_stationery', '4'
UNION ALL SELECT 'Practicises_hygienic_behaviour', '3'
UNION ALL SELECT 'Encourages_Hygiene_behaviour_in_students', '3'
UNION ALL SELECT 'Uses_Computer_independently', '3'
UNION ALL SELECT 'Able_to_work_with_software_installed', '3'
UNION ALL SELECT 'Able_to_fill_up_computer_based_MIS_independently', '3'
UNION ALL SELECT 'Employee_RefID', 'BF-005913'
UNION ALL SELECT 'Physical_Environment', '3'
UNION ALL SELECT 'TLM_DISPLAY', '3'
UNION ALL SELECT 'Emotional_Environment', '3'
UNION ALL SELECT 'Complete_Lesson_Plan', '4'
UNION ALL SELECT 'Use_of_Instructional_aids_technique', '4'
UNION ALL SELECT 'Open_ended_questioning', '4'
UNION ALL SELECT 'Active_listening', '4'
UNION ALL SELECT 'Student_talk_time', '4'
UNION ALL SELECT 'Creative_TLMs', '3'
UNION ALL SELECT 'Conduct_of_activity_based_teaching', '2'
UNION ALL SELECT 'Seating_arrangement', '3'
UNION ALL SELECT 'Effective_verbal_and_non_verbal_communication', '4'
UNION ALL SELECT 'Friendly_disposition_of_Teachers', '2'
UNION ALL SELECT 'Response_time_for_students_to_answer', '3'
UNION ALL SELECT 'Small_Group_Work', '3'
UNION ALL SELECT 'Maximizing_learning_time', '3'
UNION ALL SELECT 'Appropriate_TLM', '4'
UNION ALL SELECT 'Use_of_ICT', '3'
UNION ALL SELECT 'Organisation_of_hand_work', '2'
UNION ALL SELECT 'Appropriate_Opening', '3'
UNION ALL SELECT 'Suitable_Closing', '3'
UNION ALL SELECT 'Cooperation_of_Teacher', '4'
UNION ALL SELECT 'Courtesy_of_Teacher', '4'
UNION ALL SELECT 'Peer_assistance', '3'
UNION ALL SELECT 'Punctuality', '4'
UNION ALL SELECT 'Conduct', '3'
UNION ALL SELECT 'Grooming', '3'
UNION ALL SELECT 'Respect_for_Students_Peers', '4'
UNION ALL SELECT 'Respect_for_Community', '4'
UNION ALL SELECT 'Honesty_and_Integrity', '3'
UNION ALL SELECT 'Professional_dealing_with_parents', '4'
UNION ALL SELECT 'Helps_parents_understand_childs_needs_progress', '3'
UNION ALL SELECT 'Maintenance_of_records_proper_filling_of_MIS_economic_usage_of_stationery', '4'
UNION ALL SELECT 'Practicises_hygienic_behaviour', '3'
UNION ALL SELECT 'Encourages_Hygiene_behaviour_in_students', '3'
UNION ALL SELECT 'Uses_Computer_independently', '3'
UNION ALL SELECT 'Able_to_work_with_software_installed', '3'
UNION ALL SELECT 'Able_to_fill_up_computer_based_MIS_independently', '3'
UNION ALL SELECT 'Employee_RefID', 'BF-006038'
UNION ALL SELECT 'Physical_Environment', '4'
UNION ALL SELECT 'TLM_DISPLAY', '4'
UNION ALL SELECT 'Emotional_Environment', '3'
UNION ALL SELECT 'Complete_Lesson_Plan', '3'
UNION ALL SELECT 'Use_of_Instructional_aids_technique', '3'
UNION ALL SELECT 'Open_ended_questioning', '4'
UNION ALL SELECT 'Active_listening', '4'
UNION ALL SELECT 'Student_talk_time', '4'
UNION ALL SELECT 'Creative_TLMs', '4'
UNION ALL SELECT 'Conduct_of_activity_based_teaching', '4'
UNION ALL SELECT 'Seating_arrangement', '3'
UNION ALL SELECT 'Effective_verbal_and_non_verbal_communication', '3'
UNION ALL SELECT 'Friendly_disposition_of_Teachers', '3'
UNION ALL SELECT 'Response_time_for_students_to_answer', '4'
UNION ALL SELECT 'Small_Group_Work', '4'
UNION ALL SELECT 'Maximizing_learning_time', '4'
UNION ALL SELECT 'Appropriate_TLM', '3'
UNION ALL SELECT 'Use_of_ICT', '3'
UNION ALL SELECT 'Organisation_of_hand_work', '2'
UNION ALL SELECT 'Appropriate_Opening', '4'
UNION ALL SELECT 'Suitable_Closing', '3'
UNION ALL SELECT 'Cooperation_of_Teacher', '4'
UNION ALL SELECT 'Courtesy_of_Teacher', '4'
UNION ALL SELECT 'Peer_assistance', '4'
UNION ALL SELECT 'Punctuality', '3'
UNION ALL SELECT 'Conduct', '3'
UNION ALL SELECT 'Grooming', '4'
UNION ALL SELECT 'Respect_for_Students_Peers', '3'
UNION ALL SELECT 'Respect_for_Community', '3'
UNION ALL SELECT 'Honesty_and_Integrity', '4'
UNION ALL SELECT 'Professional_dealing_with_parents', '3'
UNION ALL SELECT 'Helps_parents_understand_childs_needs_progress', '4'
UNION ALL SELECT 'Maintenance_of_records_proper_filling_of_MIS_economic_usage_of_stationery', '3'
UNION ALL SELECT 'Practicises_hygienic_behaviour', '3'
UNION ALL SELECT 'Encourages_Hygiene_behaviour_in_students', '4'
UNION ALL SELECT 'Uses_Computer_independently', '3'
UNION ALL SELECT 'Able_to_work_with_software_installed', '3'
UNION ALL SELECT 'Able_to_fill_up_computer_based_MIS_independently', '4'
UNION ALL SELECT 'Employee_RefID', 'BF-006039'
UNION ALL SELECT 'Physical_Environment', '3'
UNION ALL SELECT 'TLM_DISPLAY', '2'
UNION ALL SELECT 'Emotional_Environment', '4'
UNION ALL SELECT 'Complete_Lesson_Plan', '4'
UNION ALL SELECT 'Use_of_Instructional_aids_technique', '4'
UNION ALL SELECT 'Open_ended_questioning', '2'
UNION ALL SELECT 'Active_listening', '4'
UNION ALL SELECT 'Student_talk_time', '4'
UNION ALL SELECT 'Creative_TLMs', '2'
UNION ALL SELECT 'Conduct_of_activity_based_teaching', '4'
UNION ALL SELECT 'Seating_arrangement', '3'
UNION ALL SELECT 'Effective_verbal_and_non_verbal_communication', '4'
UNION ALL SELECT 'Friendly_disposition_of_Teachers', '3'
UNION ALL SELECT 'Response_time_for_students_to_answer', '3'
UNION ALL SELECT 'Small_Group_Work', '2'
UNION ALL SELECT 'Maximizing_learning_time', '2'
UNION ALL SELECT 'Appropriate_TLM', '4'
UNION ALL SELECT 'Use_of_ICT', '4'
UNION ALL SELECT 'Organisation_of_hand_work', '2'
UNION ALL SELECT 'Appropriate_Opening', '3'
UNION ALL SELECT 'Suitable_Closing', '3'
UNION ALL SELECT 'Cooperation_of_Teacher', '3'
UNION ALL SELECT 'Courtesy_of_Teacher', '4'
UNION ALL SELECT 'Peer_assistance', '4'
UNION ALL SELECT 'Punctuality', '4'
UNION ALL SELECT 'Conduct', '3'
UNION ALL SELECT 'Grooming', '3'
UNION ALL SELECT 'Respect_for_Students_Peers', '3'
UNION ALL SELECT 'Respect_for_Community', '4'
UNION ALL SELECT 'Honesty_and_Integrity', '3'
UNION ALL SELECT 'Professional_dealing_with_parents', '3'
UNION ALL SELECT 'Helps_parents_understand_childs_needs_progress', '4'
UNION ALL SELECT 'Maintenance_of_records_proper_filling_of_MIS_economic_usage_of_stationery', '4'
UNION ALL SELECT 'Practicises_hygienic_behaviour', '3'
UNION ALL SELECT 'Encourages_Hygiene_behaviour_in_students', '3'
UNION ALL SELECT 'Uses_Computer_independently', '4'
UNION ALL SELECT 'Able_to_work_with_software_installed', '3'
UNION ALL SELECT 'Able_to_fill_up_computer_based_MIS_independently', '4'

DECLARE @cols VARCHAR(6000)

SET @cols = STUFF((SELECT DISTINCT '],[' + [Name]
					FROM #tmp
					ORDER BY '],[' + [Name]
			FOR XML PATH('')),1,2,'') + ']'


DECLARE @dt VARCHAR(8000)
DECLARE @pt VARCHAR(MAX)

SET @dt = N'SELECT *, ROW_NUMBER() OVER(PARTITION BY [Name] ORDER BY [Name]) AS RowID
			FROM #tmp'

SET @pt = N'SELECT RowID, ' + @cols + 
		' FROM (' + @dt + ') AS DT' +
		' PIVOT(MAX([VALUE]) FOR [Name] IN(' + @cols + ')) AS PT'
EXEC(@pt)
DROP TABLE #tmp
 
Share this answer
 
Comments
Tisha Ahuja 29-Jul-13 1:35am    
Thanks for replying Maciej Los!!
Maciej Los 29-Jul-13 2:55am    
You're welcome ;)
Please, mark this answer as a solution (green button), if it was helpful.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900