[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

microsoft.public.sqlserver.programming

To store result of stored procedure in a local variable

Priya

3/9/2007 9:10:00 AM

Hey all,

I have a query which returns the name field from a table. I use the
sp_executesql to execute this query. The code looks like,

SET @Query = 'SELECT ' + @TableName + 'Name' + 'FROM' + @TableName + '
WHERE ' + @TableName + 'ID = ' + @ID
EXEC @Name = sp_executesql @Query
SELECT @Name

IF @Name = @Value
BEGIN
........
END

I get the corresponding name from the query but the statement SELECT
@Name returns 0. I need to compare the name value with another
variable and do some more operations. How to store the name in this
procedure? Any help would be appreciated

Thanks in advance

11 Answers

Tibor Karaszi

3/9/2007 9:43:00 AM

0

You need to use output parameters with sp_executesql to get values out from the executed code. See
http://msdn2.microsoft.com/en-us/library/ms1...

--
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/d...
http://www.solidqualitylea...


"Priya" <priyavaithianathan@gmail.com> wrote in message
news:1173431404.459436.222710@v33g2000cwv.googlegroups.com...
> Hey all,
>
> I have a query which returns the name field from a table. I use the
> sp_executesql to execute this query. The code looks like,
>
> SET @Query = 'SELECT ' + @TableName + 'Name' + 'FROM' + @TableName + '
> WHERE ' + @TableName + 'ID = ' + @ID
> EXEC @Name = sp_executesql @Query
> SELECT @Name
>
> IF @Name = @Value
> BEGIN
> .......
> END
>
> I get the corresponding name from the query but the statement SELECT
> @Name returns 0. I need to compare the name value with another
> variable and do some more operations. How to store the name in this
> procedure? Any help would be appreciated
>
> Thanks in advance
>


Kirk McElhearn

12/1/2011 1:02:00 PM

0

On 2011-12-01 10:56:11 +0000, "dr.narcolepsy" <jminpa@gmail.com> said:

> I'll throw it up on fb-rmgd.

Where is that exactly? People mention it, but I've never found it.

Kirk
--

Kirkville -- http://www.mce...
Writings about more than just Macs
Take Control of iTunes 10: The FAQ: http://www.mce.../itunes

mr.rapidan

12/1/2011 2:01:00 PM

0

Someone's got to invite you, so just friend someone who's in. If you don't want to remain their friend, you can un-friend them once you're in fb-rmgd.

Kirk McElhearn

12/1/2011 3:08:00 PM

0

On 2011-12-01 14:00:41 +0000, "dr.narcolepsy" <jminpa@gmail.com> said:

> Someone's got to invite you, so just friend someone who's in. If you
> don't want to remain their friend, you can un-friend them once you're
> in fb-rmgd.

What's the name of the group? I don't know who to friend? :-)

Can you friend me and invite me?

Kirk
--

Kirkville -- http://www.mce...
Writings about more than just Macs
Take Control of iTunes 10: The FAQ: http://www.mce.../itunes

mr.rapidan

12/1/2011 3:11:00 PM

0

sure - i actually looked for you and couldn't find you - will try again

mr.rapidan

12/1/2011 3:13:00 PM

0

you've got to have a fb account - and someone has to be able to find it - or you can just friend someone else - i'm kyle fromm (there are several of us out there)

i still can't find an account under your name . . .

mr.rapidan

12/1/2011 3:15:00 PM

0

Oh - you've got to keep this quiet - sweets is actually on fb-rmgd, but he goes under the name sally forth

3jane.

12/1/2011 4:33:00 PM

0

On Dec 1, 10:15 am, "dr.narcolepsy" <jmi...@gmail.com> wrote:
> Oh - you've got to keep this quiet - sweets is actually on fb-rmgd, but he goes under the name sally forth

I wondered who that cunt was.

Kirk McElhearn

12/1/2011 4:43:00 PM

0

On 2011-12-01 15:13:26 +0000, "dr.narcolepsy" <jminpa@gmail.com> said:

> i still can't find an account under your name . . .

https://www.facebook....
--

Kirkville -- http://www.mce...
Writings about more than just Macs
Take Control of iTunes 10: The FAQ: http://www.mce.../itunes

Kirk McElhearn

12/1/2011 4:44:00 PM

0

On 2011-12-01 15:15:04 +0000, "dr.narcolepsy" <jminpa@gmail.com> said:

> Oh - you've got to keep this quiet - sweets is actually on fb-rmgd, but
> he goes under the name sally forth

Ha!

Kirk
--

Kirkville -- http://www.mce...
Writings about more than just Macs
Take Control of iTunes 10: The FAQ: http://www.mce.../itunes