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
 EXECUTE VARIABLE AND ASSING VALUE IN ANOTHER VAR

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 VARIABLE

suppose:-

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 OUTPUT
select @p
-- or print
print @p
[/code]


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2012-01-17 : 07:35:42
see here:
http://msdn.microsoft.com/de-de/library/ms188001.aspx


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

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 OUTPUT
select @p
-- or print
print @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 OUTPUT
select @p
-- or print
print @p ,@pp



how to solve above problem .

Go to Top of Page

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 print
print @p
print @pp


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page
   

- Advertisement -