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 |
paritosh
Starting Member
42 Posts |
Posted - 2012-01-17 : 07:21:11
|
I WANT TO EXECUTE VARIABLE AND ASSIGN THIS VALUE TO ANOTHER VARIABLEsuppose:-DECLARE @t VARCHAR (200), @p numeric(10)SET @t ='select 1'set @p=exec (@t)and after print @p result is 1 |
|
webfred
Master Smack Fu Yak Hacker
8781 Posts |
Posted - 2012-01-17 : 07:34:54
|
[code]DECLARE @t NVARCHAR (200)DECLARE @p numeric(10)DECLARE @ParmDefinition nvarchar(500)SET @t ='select @p_out = 1'set @ParmDefinition='@p_out numeric(10) OUTPUT'--set @p=exec (@t)execute sp_executesql @t, @ParmDefinition, @p_out=@p OUTPUTselect @p-- or printprint @p[/code] No, you're never too old to Yak'n'Roll if you're too young to die. |
|
|
webfred
Master Smack Fu Yak Hacker
8781 Posts |
|
paritosh
Starting Member
42 Posts |
Posted - 2012-01-18 : 23:46:35
|
quote: Originally posted by webfred
DECLARE @t NVARCHAR (200)DECLARE @p numeric(10)DECLARE @ParmDefinition nvarchar(500)SET @t ='select @p_out = 1'set @ParmDefinition='@p_out numeric(10) OUTPUT'--set @p=exec (@t)execute sp_executesql @t, @ParmDefinition, @p_out=@p OUTPUTselect @p-- or printprint @p No, you're never too old to Yak'n'Roll if you're too young to die.
hi, thanks for above solution....if i have two or three variables then how to do.for example :-DECLARE @t NVARCHAR (200)DECLARE @p numeric(10)declare @pp numeric(10)DECLARE @ParmDefinition nvarchar(500)SET @t ='select @p_out = 1, @pp_out =2'set @ParmDefinition='@p_out numeric(10) OUTPUT'--set @p=exec (@t)execute sp_executesql @t, @ParmDefinition, @p_out=@p OUTPUTselect @p-- or printprint @p ,@pphow to solve above problem . |
|
|
webfred
Master Smack Fu Yak Hacker
8781 Posts |
Posted - 2012-01-19 : 04:45:41
|
DECLARE @t NVARCHAR (200)DECLARE @p numeric(10)declare @pp numeric(10)DECLARE @ParmDefinition nvarchar(500)SET @t ='select @p_out = 1, @pp_out =666'set @ParmDefinition='@p_out numeric(10) OUTPUT, @pp_out numeric(10) OUTPUT'--set @p=exec (@t)execute sp_executesql @t, @ParmDefinition, @p_out=@p OUTPUT, @pp_out=@pp OUTPUT--select @p-- or printprint @pprint @pp No, you're never too old to Yak'n'Roll if you're too young to die. |
|
|
|
|
|
|
|