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
 General SQL Server Forums
 New to SQL Server Programming
 Regarding local variables

Author  Topic 

srxr9
Starting Member

15 Posts

Posted - 2006-09-25 : 12:53:24
declare @Id integer
set @Id=1145
select '@'+'Id'

result: @Id

But I want the result to be 1145. Is it possible, If so please let me know how.

Thanks
Suresh

snSQL
Master Smack Fu Yak Hacker

1837 Posts

Posted - 2006-09-25 : 12:55:02
[code]declare @Id int
set @Id=1145
select @Id[/code]
Go to Top of Page

TG
Master Smack Fu Yak Hacker

6065 Posts

Posted - 2006-09-25 : 13:22:19
Is your question that you want to build local variables dynamically? You would need to use dynamic sql for that. There is probably a standard technique already devised for whatever your objective is if you want to tell us what that is. :)

Be One with the Optimizer
TG
Go to Top of Page

srxr9
Starting Member

15 Posts

Posted - 2006-09-25 : 13:51:19
Yes, I am trying to build a dynamic query.
I have a variable that returns 'Id'
and there is already a variable declared as @Id.
I am trying to retrieve the value of @Id using the variable that returns 'ID'

For example:
declare @Id integer
set @Id=1145
declare @Id1 varchar(10)
set @Id1 = 'ID'
select '@'+@Id1

result: @ID

but I want it as 1145.


Thanks
Suresh

Go to Top of Page

Michael Valentine Jones
Yak DBA Kernel (pronounced Colonel)

7020 Posts

Posted - 2006-09-25 : 14:07:02
What is it you are trying to accomplish? I can't really tell from the code you posted.

CODO ERGO SUM
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2006-09-25 : 19:37:53
" Yes, I am trying to build a dynamic query."
Take a look here. http://www.sommarskog.se/dynamic_sql.html


KH

Go to Top of Page
   

- Advertisement -