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

sql query Expand / Collapse
Author
Message
Posted Sunday, January 20, 2013 10:03 PM
SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Today @ 9:39 AM
Points: 166, Visits: 3,880
hi friends i have a samll doubt in sql server plese tell me how to solve this one table data contains like
i have table containing 3 columns :
Col1, Col2 and Col3. There is only 1 row in the table as follows:

Col1Col2Col3
-----------------
a b c
i want output like this way

Col
-----
a
b
c
plese tell me how to write query in sql server
Post #1409347
Posted Monday, January 21, 2013 1:34 AM
Valued Member

Valued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued Member

Group: General Forum Members
Last Login: Monday, June 03, 2013 9:31 PM
Points: 53, Visits: 151
select Col
from (select * from dbo.TESTTB) as X
unpivot (Col for cols in (col1, col2, col3)) as Y
Post #1409399
Posted Monday, January 21, 2013 1:38 AM


SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Thursday, June 13, 2013 7:03 AM
Points: 2,562, Visits: 3,453
it will be easy for people if you post the table defifntion (create stmt) along with some sampoled data plus expected output.people generally steal some time from their busy scehdules to help other people and often they dont have time to frame everything on theri own (and sometime people are too lazy like me which are reluctant to do this ) so better do these things to get the result faster. See link in my signature below

-------Bhuvnesh----------
While 1 = 1 (Learning SQL....)
Click to get fast response of your post
Post #1409404
Posted Monday, January 21, 2013 5:51 PM


SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Today @ 12:22 AM
Points: 2,370, Visits: 3,250
Try using DelimitedSplit8K: http://www.sqlservercentral.com/articles/Tally+Table/72993/


No loops! No CURSORs! No RBAR! Hoo-uh!

INDEXing a poor-performing query is like putting sugar on cat food. Yeah, it probably tastes better but are you sure you want to eat it?

Need to UNPIVOT? Why not CROSS APPLY VALUES instead?
Since random numbers are too important to be left to chance, let's generate some!
Are you too recursively challenged?
Splitting strings based on patterns can be fast!
Post #1409755
Posted Monday, January 21, 2013 6:01 PM


Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Today @ 9:33 AM
Points: 1,333, Visits: 4,017
DECLARE @t table(Col1 char(1),Col2 char(1),Col3 char(1));

INSERT @t(Col1,Col2,Col3)
VALUES('a','b','c');

SELECT Col
FROM @t as T
CROSS APPLY (VALUES(Col1),(Col2),(Col3)) AS CA(Col);



MM




Post #1409756
Posted Monday, January 21, 2013 6:08 PM


SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Today @ 12:22 AM
Points: 2,370, Visits: 3,250
mister.magoo (1/21/2013)
DECLARE @t table(Col1 char(1),Col2 char(1),Col3 char(1));

INSERT @t(Col1,Col2,Col3)
VALUES('a','b','c');

SELECT Col
FROM @t as T
CROSS APPLY (VALUES(Col1),(Col2),(Col3)) AS CA(Col);



Silly me. I thought he was trying to split a delimited string.



No loops! No CURSORs! No RBAR! Hoo-uh!

INDEXing a poor-performing query is like putting sugar on cat food. Yeah, it probably tastes better but are you sure you want to eat it?

Need to UNPIVOT? Why not CROSS APPLY VALUES instead?
Since random numbers are too important to be left to chance, let's generate some!
Are you too recursively challenged?
Splitting strings based on patterns can be fast!
Post #1409759
Posted Monday, January 21, 2013 6:11 PM


Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Today @ 9:33 AM
Points: 1,333, Visits: 4,017
dwain.c (1/21/2013)


Silly me. I thought he was trying to split a delimited string.


Jury is still out on that...


MM




Post #1409760
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse