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 |
|
khufiamalik
Posting Yak Master
120 Posts |
Posted - 2008-08-13 : 05:27:51
|
| Hello All,I have a query in a variable and i want to store it's resultant in another variable , how can I do itMy Query is like 'Select EmployeeSalary from Employee'Waiting for your kind replyregardsYasir Mehmood |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-08-13 : 05:29:19
|
| Select @yourvariable=EmployeeSalary from Employeebut make sure the query is returning only a single value as variable can hold only a single value not a resultset. |
 |
|
|
khufiamalik
Posting Yak Master
120 Posts |
Posted - 2008-08-13 : 05:31:43
|
| actullay query is being passed from some external module and it is complete query including SELECT statement.Is there any other way to do this? |
 |
|
|
bhuvnesh.dogra
Starting Member
22 Posts |
Posted - 2008-08-13 : 06:53:04
|
| Below is your solution but you nedd to execute all stuff in one transaction..-------------------------------------------------declare @tbl_variable table (nam varchar(40))insert into @tbl_variableSELECT top 10 [name] FROM SYSOBJECTS ORDER BY [name] COLLATE Latin1_General_CI_AIselect * from @tbl_variable |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-08-13 : 07:45:18
|
| or use # table |
 |
|
|
Transact Charlie
Master Smack Fu Yak Hacker
3451 Posts |
Posted - 2008-08-13 : 07:56:30
|
quote: Originally posted by bhuvnesh.dogra Below is your solution but you need to execute all stuff in one transaction..-------------------------------------------------declare @tbl_variable table (nam varchar(40))insert into @tbl_variableSELECT top 10 [name] FROM SYSOBJECTS ORDER BY [name] COLLATE Latin1_General_CI_AIselect * from @tbl_variable
Sorry bhuvnesh.dogra I don't see how this will help OP unless this SELECT top 10 [name] FROM SYSOBJECTS ORDER BY [name] COLLATE Latin1_General_CI_AI happens to be the query he wants (which I don't think it is)He's getting a dynamic query back from something as a string. So he'll have to execute that dynamically. Therefore he can't use a table variable because it won't exists in the scope of his dynamic call.visakh16 : Yes he could use a temp table but it's not what he's after.khufiamalik - someone raised exactly this problem a few hours ago and I explained a solution to them.Check out http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=108730-------------Charlie |
 |
|
|
Transact Charlie
Master Smack Fu Yak Hacker
3451 Posts |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
|
|
|
|
|