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 on Query

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 data

Parameter SelectedValue
Param1 1
Param2 2
Param3 3

Is there any query or SP, which will give me the result set as
Param1 Param2 Param3
1 2 3

Can some one please help

jonasalbert20
Constraint Violating Yak Guru

300 Posts

Posted - 2008-03-18 : 05:50:55
see this topic http://sqlteam.com/item.asp?ItemID=2955






For fast result follow this...
http://weblogs.sqlteam.com/brettk/archive/2005/05/25.aspx

Want Philippines to become 1st World COuntry? Go for World War 3...
Go to Top of Page

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 data

Parameter SelectedValue
Param1 1
Param2 2
Param3 3

Is there any query or SP, which will give me the result set as
Param1 Param2 Param3
1 2 3

Can some one please help


What do you want to display if there are hundreds of values?

Madhivanan

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

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 all
Select 'Param2', 2 union all
Select 'Param3', 3 union all
Select 'Param4', 4 union all
Select 'Param5', 5 union all
Select 'Param5', 6 union all
Select 'Param6', 6


--Select * From #Temp

Declare @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 @sql

Select @str = @str + 'Select SelectedValue '+(@sql)+' From #Temp Group BY SelectedValue'

print (@Str)
Exec (@str)



Drop Table #Temp


Go to Top of Page

dass05555
Yak Posting Veteran

55 Posts

Posted - 2008-03-18 : 07:21:24
u can try the "pivot"
function

regards
dass
Go to Top of Page

elancaster
A very urgent SQL Yakette

1208 Posts

Posted - 2008-03-18 : 07:22:36
quote:

-dass

u can try the "pivot"
function



...not in SQL2000

Em
Go to Top of Page

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 like
Currently i am getting the result set like this
Selected Value Param1 Param2 Param3 Param4 Param5 Param6
1 1 NULL NULL NULL NULL NULL
2 NULL 2 NULL NULL NULL NULL
3 NULL NULL 3 NULL NULL NULL
4 NULL NULL NULL 4 NULL NULL
5 NULL NULL NULL NULL 5 NULL
6 NULL NULL NULL NULL 6 6


Can i get it in this format.
Param1 Param2 Param3 Param4 Param5 Param6
1 2 3 4 5 6

Thanks,
Jai
Go to Top of Page

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
Go to Top of Page
   

- Advertisement -