By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,950 Members | 986 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,950 IT Pros & Developers. It's quick & easy.

Stored Procedure retrieve Parameter values from variable

P: 2
Is there any way to get parameter value from variable

like

@Param1 varchar(50)
@Param2 varchar(50)
set Param1 ='value1'

while --condition--
begin
---statement---
@Param2='Param1'

---?How can I retrieve the value of Parameter that is in @Param2
so I can get data of Parameter that

At last I can get value of @Param1 from @Param2 i.e. 'value1'
Sep 27 '07 #1
Share this Question
Share on Google+
3 Replies


azimmer
Expert 100+
P: 200
Is there any way to get parameter value from variable

like

@Param1 varchar(50)
@Param2 varchar(50)
set Param1 ='value1'

while --condition--
begin
---statement---
@Param2='Param1'

---?How can I retrieve the value of Parameter that is in @Param2
so I can get data of Parameter that

At last I can get value of @Param1 from @Param2 i.e. 'value1'
It depends on what you want to do it after you got it. If you can process it clear an short, compile a statement in a variable then execute it:
Expand|Select|Wrap|Line Numbers
  1. declare @Param1 varchar(50)
  2. declare @Param2 varchar(50)
  3. declare @sql varchar(128)
  4. set @Param1 ='value1'
  5. set @Param2='Param1'
  6. set @sql='print '''+@Param1+''''
  7. exec(@sql)
  8.  
It's OK so long as you can confine your processing to an SQL string. The only way I know of to "bring" the value of anything "out of" the exec "context" is to insert it into a table. So if you need a lot of calculations you have to set up an extra table for this...
Sep 27 '07 #2

P: 2
It depends on what you want to do it after you got it. If you can process it clear an short, compile a statement in a variable then execute it:
Expand|Select|Wrap|Line Numbers
  1. declare @Param1 varchar(50)
  2. declare @Param2 varchar(50)
  3. declare @sql varchar(128)
  4. set @Param1 ='value1'
  5. set @Param2='Param1'
  6. set @sql='print '''+@Param1+''''
  7. exec(@sql)
  8.  
It's OK so long as you can confine your processing to an SQL string. The only way I know of to "bring" the value of anything "out of" the exec "context" is to insert it into a table. So if you need a lot of calculations you have to set up an extra table for this...
thank you,

I want to know is this possible using @param2 to get value of @Param1

set @sql='print '''+@Param1+''''

here i want to use @param2 to get value that is stored in @Param1

using
declare @Param1 varchar(50)
declare @Param2 varchar(50)
declare @sql varchar(128)
set @Param1 ='value1'
set @Param2='Param1'
print ''+'@'+ @Param2 +''+''

this I get
@Param1

but i need value stored in @Param1
Sep 28 '07 #3

P: 1
thank you,

I want to know is this possible using @param2 to get value of @Param1

set @sql='print '''+@Param1+''''

here i want to use @param2 to get value that is stored in @Param1

using
declare @Param1 varchar(50)
declare @Param2 varchar(50)
declare @sql varchar(128)
set @Param1 ='value1'
set @Param2='Param1'
print ''+'@'+ @Param2 +''+''

this I get
@Param1

but i need value stored in @Param1

You are getting the value '@Param1' in your output because you have assigned 'Param1' to the variable @Param2.

Expand|Select|Wrap|Line Numbers
  1. set @Param2='Param1'
What you should have typed on this line is...

Expand|Select|Wrap|Line Numbers
  1. set @Param2 = @Param1
This will assign the value that the variable @Param1 contains to @Param2.

Hope this helps.
Oct 5 '07 #4

Post your reply

Sign in to post your reply or Sign up for a free account.