Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 need help in query..

Author  Topic 

cyberpd
Yak Posting Veteran

60 Posts

Posted - 2007-07-05 : 07:31:53
suppose there is a table with 4 columns and only 1 row.
for example T(A1,A2,A3,A4).

now i need the data vertically.
i mean i need a view of the data with 1 column and 4 rows.

I don't know if this is possible.
Any suggestions / help is appreciated.

thanks and regards.

Dallr
Yak Posting Veteran

87 Posts

Posted - 2007-07-05 : 07:34:21
Not answering your question but commenting on your table structure. It seems to me that you have repeating groups in your table which shouldn't be.

Dane
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-07-05 : 07:34:36
Assuming all four columns are of same datatype
SELECT Col1 AS theCol FROM Table1
UNION ALL
SELECT Col2 FROM Table1
UNION ALL
SELECT Col3 FROM Table1
UNION ALL
SELECT Col4 FROM Table1


Peter Larsson
Helsingborg, Sweden
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2007-07-05 : 07:35:49
[code]SELECT A1 AS A FROM T UNION ALL
SELECT A2 AS A FROM T UNION ALL
SELECT A3 AS A FROM T UNION ALL
SELECT A4 AS A FROM T[/code]


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2007-07-05 : 07:36:23



KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

cyberpd
Yak Posting Veteran

60 Posts

Posted - 2007-07-05 : 08:18:03
thanks all of you for the reply..

that's what i want with little modification.

i need to add a where clause like the following

SELECT Col1 FROM Table1 WHERE C1=T.C1
UNION ALL
SELECT Col2 FROM Table1 WHERE C1=T.C1
UNION ALL
SELECT Col3 FROM Table1 WHERE C1=
T.C1
UNION ALL
SELECT Col4 FROM Table1 WHERE C1=T.C1

Now I need to give this T.C1 from same table, and value will go once.


thanks and regards
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-07-05 : 09:15:36
Oh man!
What is C1? What is T.C1?

Please, please post full and utterly complete problem description so we don't have to guess

Post sample data and expected output.


Peter Larsson
Helsingborg, Sweden
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2007-07-05 : 10:31:35
Where do you want to show data?

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

cyberpd
Yak Posting Veteran

60 Posts

Posted - 2007-07-06 : 05:08:37
thanks peso , madhivanan for the concern..

i think i can solve the problem in another way.
i mean using functions and stored procedures..

thanks and regards
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-07-06 : 05:18:31
Good luck!


Peter Larsson
Helsingborg, Sweden
Go to Top of Page
   

- Advertisement -