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.
Author |
Topic |
jai2808
Starting Member
27 Posts |
Posted - 2008-03-18 : 05:42:59
|
Hi,I have a table which has got the following structure and dataParameter SelectedValueParam1 1Param2 2Param3 3Is there any query or SP, which will give me the result set as Param1 Param2 Param31 2 3Can some one please help |
|
jonasalbert20
Constraint Violating Yak Guru
300 Posts |
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2008-03-18 : 06:59:22
|
quote: Originally posted by jai2808 Hi,I have a table which has got the following structure and dataParameter SelectedValueParam1 1Param2 2Param3 3Is there any query or SP, which will give me the result set as Param1 Param2 Param31 2 3Can some one please help
What do you want to display if there are hundreds of values?MadhivananFailing to plan is Planning to fail |
 |
|
ranganath
Posting Yak Master
209 Posts |
Posted - 2008-03-18 : 07:15:31
|
Hi,Try with this Create Table #Temp ( id int Identity(1,1), Parameter Varchar(1000), SelectedValue INT)Insert Into #Temp Select 'Param1', 1 union allSelect 'Param2', 2 union allSelect 'Param3', 3 union allSelect 'Param4', 4 union allSelect 'Param5', 5 union allSelect 'Param5', 6 union allSelect 'Param6', 6 --Select * From #TempDeclare @Sql Varchar(8000)Set @sql = ''DEclare @str Varchar(8000)Set @str = ''Select @sql = @sql + ', Max(Case when Parameter = ''' +Parameter + ''' Then SelectedValue End ) AS "' + Parameter + '"' From (Select distinct Parameter From #Temp)a--Select @sqlSelect @str = @str + 'Select SelectedValue '+(@sql)+' From #Temp Group BY SelectedValue'print (@Str)Exec (@str)Drop Table #Temp |
 |
|
dass05555
Yak Posting Veteran
55 Posts |
Posted - 2008-03-18 : 07:21:24
|
u can try the "pivot"functionregardsdass |
 |
|
elancaster
A very urgent SQL Yakette
1208 Posts |
Posted - 2008-03-18 : 07:22:36
|
quote: -dassu can try the "pivot"function
...not in SQL2000Em |
 |
|
jai2808
Starting Member
27 Posts |
Posted - 2008-03-22 : 01:37:03
|
Hi ranganath,Thanks for the reply, can i get it one single row likeCurrently i am getting the result set like thisSelected Value Param1 Param2 Param3 Param4 Param5 Param61 1 NULL NULL NULL NULL NULL2 NULL 2 NULL NULL NULL NULL3 NULL NULL 3 NULL NULL NULL4 NULL NULL NULL 4 NULL NULL5 NULL NULL NULL NULL 5 NULL6 NULL NULL NULL NULL 6 6Can i get it in this format.Param1 Param2 Param3 Param4 Param5 Param6 1 2 3 4 5 6 Thanks,Jai |
 |
|
jai2808
Starting Member
27 Posts |
Posted - 2008-03-24 : 09:09:18
|
Hi ranganath,Thanks a ton, I working amazingly.Thanks once again.Thanks,JP |
 |
|
|
|
|
|
|