dbTalk Databases Forums  

Re: exec command

microsoft.public.sqlserver.mseq microsoft.public.sqlserver.mseq


Discuss Re: exec command in the microsoft.public.sqlserver.mseq forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
peeyush agrawal
 
Posts: n/a

Default Re: exec command - 07-15-2003 , 09:12 AM






Thanks a lot Vishal and Anith

"Vishal Parkar" <vgparkar (AT) hotmail (DOT) com> wrote

Quote:
In addition to anith's post try this, something similar to what you want
on
northwind database:

declare @comp varchar(20)
exec sp_executesql N'select @comp =
(select customerid from customers where customerid=''ALFKI'')',N'@comp
varchar(20) output', @comp output
print @comp

--
-Vishal
peeyush agrawal <peeyush.agrawal (AT) cendant (DOT) com> wrote in message
news:OMFrxXkSDHA.1588 (AT) TK2MSFTNGP11 (DOT) phx.gbl...
how can I set the vaule of a sql result in a variable

for e.g

declare
@comp varchar(20),

select @comp = (select compid from company)
print @comp

But if my sql string is dynamic how would I use it ?



declare
@comp varchar(20)
@str1 varchar

select @str1 = 'select compid from company'

select @comp = exec @str1 ---------???????????????

Please help and thnaks in advance








Reply With Quote
  #2  
Old   
Vishal Parkar
 
Posts: n/a

Default Re: exec command - 07-15-2003 , 02:36 PM






In addition to anith's post try this, something similar to what you want on
northwind database:

declare @comp varchar(20)
exec sp_executesql N'select @comp =
(select customerid from customers where customerid=''ALFKI'')',N'@comp
varchar(20) output', @comp output
print @comp

--
-Vishal
peeyush agrawal <peeyush.agrawal (AT) cendant (DOT) com> wrote

Quote:
how can I set the vaule of a sql result in a variable

for e.g

declare
@comp varchar(20),

select @comp = (select compid from company)
print @comp

But if my sql string is dynamic how would I use it ?



declare
@comp varchar(20)
@str1 varchar

select @str1 = 'select compid from company'

select @comp = exec @str1 ---------???????????????

Please help and thnaks in advance






Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.