Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

split columns Expand / Collapse
Author
Message
Posted Thursday, October 7, 2010 10:49 AM
Valued Member

Valued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued Member

Group: General Forum Members
Last Login: Monday, December 6, 2010 10:01 PM
Points: 62, Visits: 40
Hai,

I have the script output LIKe ' [product_id_1], [scan_time__sec], [focal_spot_mm], [gray_scale_bit], [detector_resolution_mm], [dimension], [image_acquisition_degree_rotation], [source_url1], [source_url2]'

This all column name, I need to split into seperate all columns like
[product_id_1]
[scan_time__sec]
[focal_spot_mm]
[gray_scale_bit]

Can someone guide me how need to split columns.

Thanks.
ARP
Post #1000709
Posted Thursday, October 7, 2010 2:27 PM


SSC-Dedicated

SSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-Dedicated

Group: Administrators
Last Login: Today @ 1:28 PM
Points: 31,368, Visits: 15,836
You are showing separate rows, not columns. If that what you mean?

Is this a string you are splitting or are these columns somehow that have data in them?







Follow me on Twitter: @way0utwest

Forum Etiquette: How to post data/code on a forum to get the best help
Post #1000900
Posted Thursday, October 7, 2010 3:19 PM


SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Sunday, August 17, 2014 3:10 PM
Points: 2,787, Visits: 6,098
You seem to be trying to turn columns into rows. Will one of the solutions below work for you?

declare @sample table ([product_id_1] int, 
[scan_time__sec] int,
[focal_spot_mm] int,
[gray_scale_bit] int,
[detector_resolution_mm] int,
[dimension] int,
[image_acquisition_degree_rotation] int,
[source_url1] int,
[source_url2] int)

insert into @sample
select 1,2,3,4,5,6,7,8,9

select product_id_1,scan_time__sec, focal_spot_mm, gray_scale_bit from @sample



select ca.*
from @sample s
cross apply (
values
('product_id_1',product_id_1),
('scan_time_sec',scan_time__sec),
('focal_spot_mm',focal_spot_mm ),
('gray_scale_bit',gray_scale_bit )
) ca (colName,colValue)


select product_id_1,ca.*
from @sample s
cross apply (
values
('scan_time_sec',scan_time__sec),
('focal_spot_mm',focal_spot_mm ),
('gray_scale_bit',gray_scale_bit )
) ca (colName,colValue)





__________________________________________________

Against stupidity the gods themselves contend in vain. -- Friedrich Schiller
Stop, children, what's that sound? -- Stephen Stills
Post #1000933
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse