Results 1 to 3 of 3
  1. #1
    Join Date
    Nov 2004
    Posts
    39

    Unanswered: sp_executesql question

    I have this code:
    declare @a nvarchar(300), @camp nvarchar(15)

    select @camp = camp from ref_activtot_paracnet where tip = 16011

    set @a = 'select top 1 '+@camp+' from paracnet where datacalc = ''1/1/2005'''

    exec sp_executesql @a

    How can I store the value returned by the exec sp_executesql statement into a variable?

  2. #2
    Join Date
    Jun 2003
    Posts
    269
    Code:
    declare @a nvarchar(300), @campoutput nvarchar(15)
    --select @camp = camp from ref_activtot_paracnet where tip = 16011
    set @a = 'select top 1 @camp = camp from paracnet where datacalc = ''1/1/2005'''
    exec sp_executesql @a,
         N'@camp nvarchar(15) output',
         @camp = @campoutput OUTPUT 
    print @campoutput
    I love cursor,though I never use it.Cos' I dont want to misuse it.
    ----------------------------------------------

    ----cheers
    ----http://mallier.blogspot.com

  3. #3
    Join Date
    Nov 2004
    Posts
    39
    thx
    it's great

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •