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 Veteran

SSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC Veteran

Group: General Forum Members
Last Login: Friday, September 12, 2014 2:11 AM
Points: 211, Visits: 4,540
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: Wednesday, October 8, 2014 2:46 AM
Points: 55, Visits: 159
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: Tuesday, October 21, 2014 2:36 AM
Points: 2,840, Visits: 3,970
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----------
I work only to learn Sql Server...though my company pays me for getting their stuff done
Post #1409404
Posted Monday, January 21, 2013 5:51 PM


Hall of Fame

Hall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of Fame

Group: General Forum Members
Last Login: Tuesday, October 7, 2014 10:53 PM
Points: 3,421, Visits: 5,359
Try using DelimitedSplit8K: http://www.sqlservercentral.com/articles/Tally+Table/72993/


My mantra: No loops! No CURSORs! No RBAR! Hoo-uh!

My thought question: Have you ever been told that your query runs too fast?

My advice:
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?
The path of least resistance can be a slippery slope. Take care that fixing your fixes of fixes doesn't snowball and end up costing you more than fixing the root cause would have in the first place.


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


SSCommitted

SSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommitted

Group: General Forum Members
Last Login: Yesterday @ 5:32 PM
Points: 1,796, Visits: 5,801
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


  • MMGrid Addin
  • MMNose Addin


  • Forum Etiquette: How to post Reporting Services problems
  • Forum Etiquette: How to post data/code on a forum to get the best help - by Jeff Moden
  • How to Post Performance Problems - by Gail Shaw

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


    Hall of Fame

    Hall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of Fame

    Group: General Forum Members
    Last Login: Tuesday, October 7, 2014 10:53 PM
    Points: 3,421, Visits: 5,359
    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.



    My mantra: No loops! No CURSORs! No RBAR! Hoo-uh!

    My thought question: Have you ever been told that your query runs too fast?

    My advice:
    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?
    The path of least resistance can be a slippery slope. Take care that fixing your fixes of fixes doesn't snowball and end up costing you more than fixing the root cause would have in the first place.


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


    SSCommitted

    SSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommitted

    Group: General Forum Members
    Last Login: Yesterday @ 5:32 PM
    Points: 1,796, Visits: 5,801
    dwain.c (1/21/2013)


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


    Jury is still out on that...


    MM


  • MMGrid Addin
  • MMNose Addin


  • Forum Etiquette: How to post Reporting Services problems
  • Forum Etiquette: How to post data/code on a forum to get the best help - by Jeff Moden
  • How to Post Performance Problems - by Gail Shaw

  • Post #1409760
    « Prev Topic | Next Topic »

    Add to briefcase

    Permissions Expand / Collapse