![]() | |
![]() |
| | Thread Tools | Display Modes |
#1
| |||
| |||
|
|
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 |
#2
| |||
| |||
|
|
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 |
![]() |
| Thread Tools | |
| Display Modes | |
| |