|
Hi, I am working on a application and i need to output some comma seperated values stored in a single column to a seperate rows or columns. The below is the original output of the Selectc Query.
In the desired output the comma seperated values of Item_Type ie R,U must be displayed in seperate rows and the appropriate Item_Qty for R and U must be displayed in the next column. The desired output must look alike the below one
I dont know how to code this one as I am a beginner of sql. I will be having only select access in the database and so i cannot run any cursors, views and other things to perform this. Any help regarding this is very much appreciated. Thanks in advance... Regards, Karthik
(comments are locked)
|
|
OK, I guess this is one way of doing it. First, I pivoted the data to get the ROWS into COLUMNS, then Split the comma delimited data into rows using CHARINDEX (Since you mention only 1 comma this was easy, but if the delimited values are more than four or so then you may have to use the cteTally) EDIT: Changed the code to be compatible with versions like SQL 2000
(comments are locked)
|
|
Hi Usman, Thank you for the query.. Your query is working well in my local machine. but the problem is in my application server. since i have only select permission, i will not be able to execute queries having pivots due to the reason of db compatiblity. Is there any way to work around without using pivot tables? Yes there is a workaround and I have edited my answer accordingly. But you did tag the question against SQL 2008 ;)
Jul 16 '12 at 09:11 AM
Usman Butt
(comments are locked)
|




@Karthik Venkatraman Please post the data in a format which can be copied OR best would be to post the DDLs of the table, DATA-INSERTION script and the desired output. This way you have more chances getting a swift response.