Results 1 to 3 of 3

Thread: Dynamic sql

  1. #1
    Join Date
    Mar 2009
    Posts
    47

    Question Unanswered: Dynamic sql

    Hi,
    Please shed some light on the following..
    I am getting an error incorrect syntax near FROM
    Please help
    SET @ParmDefinition = N'@SubjectListOUT nvarchar(max) OUTPUT'
    set @SQLQuery =N' SELECT Top(1) STUFF(( SELECT distinct '','' + subname
    FROM '+@TableName +' b

    FOR XML PATH('')
    ), 1, 1, '') AS SubjectList
    FROM '+@TableName +' a'
    EXECUTE sp_executesql @SQLQuery,
    @ParmDefinition, @SubjectListOUT=@SUBJECTLIST OUTPUT

    set @subjectlist =REPLACE (@subjectlist,'&',' & ')

  2. #2
    Join Date
    Jan 2007
    Location
    UK
    Posts
    11,434
    Provided Answers: 10
    Full procedure code please.
    George
    Home | Blog

  3. #3
    Join Date
    Mar 2009
    Posts
    47

    Dynamic sql

    CREATE PROCEDURE [dbo].[RevalResultPublish]
    @COURSE_ID NVARCHAR(50)=NULL,
    @COURSE_NAME NVARCHAR(50)=NULL,
    @SUBJECTLIST AS NVARCHAR(MAX),
    @myReval dbo.myrevalresult READONLY

    AS
    BEGIN
    SET NOCOUNT ON;
    DECLARE @TableName as NVARCHAR(20)
    DECLARE @SQLQuery AS NVARCHAR(MAX)

    DECLARE @ParmDefinition nvarchar(500)
    declare @NewTableName sysname

    SET @TableName ='Apr'+@COURSE_ID


    SET @ParmDefinition = N'@SubjectListOUT nvarchar(max) OUTPUT'
    set @SQLQuery =N' SELECT Top(1) STUFF(( SELECT distinct '','' + subname
    FROM '+@TableName +' b

    FOR XML PATH('')
    ), 1, 1, '') AS SubjectList
    FROM '+@TableName +' a'
    EXECUTE sp_executesql @SQLQuery,
    @ParmDefinition, @SubjectListOUT=@SUBJECTLIST OUTPUT

    set @subjectlist =REPLACE (@subjectlist,'&',' & ')





    end

Posting Permissions

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