Results 1 to 2 of 2

Thread: dynamic sql ..pls help

  1. #1
    Join Date
    Sep 2002
    Posts
    5

    dynamic sql ..pls help

    declare @fullname varchar(200)
    declare @sqlstmt nvarchar(2000)
    declare @from varchar(200)

    select @fullname='nm_last'","'wpat.nm_first'
    select @from =' from w_patient wpat'


    set @sqlstmt=N'select '+ @fullname + @from
    EXEC sp_executesql @sqlstmt

    This give error...

  2. #2
    Join Date
    Oct 2002
    Posts
    1
    Hi,

    The error is on the following line, it complaining about the comma within the double quotes:

    select @fullname='nm_last'","'wpat.nm_first'

    Since its a string you'll need to either:

    a) have the whole column(s) within a string eg,

    select @fullname='nm_last, wpat.nm_first'

    b) concatenate the strings. eg,

    select @fullname=='nm_last' + ',' + 'wpat.nm_first'

Posting Permissions

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