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 2005 Forums
 Transact-SQL (2005)
 How to store values in Variable in SP

Author  Topic 

khufiamalik
Posting Yak Master

120 Posts

Posted - 2008-08-15 : 08:01:15
i have a query like this
Select Col1,Col2,Col3 from MyTable where Col1=1

which gives me a single row.


I have been using this query in my SP and just want to store all these values in individual Variable (with in that SP).

Can any one help me in this regard?

TG
Master Smack Fu Yak Hacker

6065 Posts

Posted - 2008-08-15 : 08:19:50
how do you want to use this variable once you have it? You could use a table variable, or xml, or a csv string...

Be One with the Optimizer
TG
Go to Top of Page

khufiamalik
Posting Yak Master

120 Posts

Posted - 2008-08-15 : 08:22:47
Actually I have 3 variables var1,var2,var3
and I have a query
Select Col1,Col2,Col3 from MyTable where Col1=1

I just want to have values like var1= Col1 ,var2=Col2,var3=Col3
Go to Top of Page

elancaster
A very urgent SQL Yakette

1208 Posts

Posted - 2008-08-15 : 08:24:26
select @var1 = col1, @var2 = col2, @var3 = col3
from MyTable where Col1=1


Em
Go to Top of Page

khufiamalik
Posting Yak Master

120 Posts

Posted - 2008-08-15 : 08:31:57
Thank You, You solved my problem
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-08-15 : 11:54:58
Are you sure you'll be having single record returned satisfying the above condition? ELse you need to use a table varaible as suggested earlier.
Go to Top of Page
   

- Advertisement -