Results 1 to 3 of 3

Thread: Insert into @parm syntax problem

  1. #1
    Judith Farber Abraham Guest

    Insert into @parm syntax problem

    I am writing a stored procedure:
    CREATE PROCEDURE rasp_FillDescrColumnNames
    @TableNameD varchar(50),
    @TableNameU varchar(50),
    @TableUID int
    --
    --
    AS
    ......

    Insert into @TableNameD(ColumnName)
    Select #TempColumnNames.Name
    From #TempColumnNames

    -----------------------------
    I get "incorrect syntax near '@TableName'". (The input table does have a column called 'ColumnName&#39. How do you parametized an 'Insert Into' sql statement? I have tried a number of ways to no avail.
    Thanks,
    Judith


  2. #2
    Brian K. Guest

    Insert into @parm syntax problem (reply)


    Here is the way to do it:

    (inside the procedure add this code

    declare @Str varchar(255)

    select @Str = ('Insert into ' + @TableNameD + '(ColumnName) Select #TempColumnNames.Name From #TempColumnNames)'

    EXec (@Str)


    Good Luck
    ------------
    Judith Farber Abraham at 9/29/99 12:43:32 PM

    I am writing a stored procedure:
    CREATE PROCEDURE rasp_FillDescrColumnNames
    @TableNameD varchar(50),
    @TableNameU varchar(50),
    @TableUID int
    --
    --
    AS
    ......

    Insert into @TableNameD(ColumnName)
    Select #TempColumnNames.Name
    From #TempColumnNames

    -----------------------------
    I get "incorrect syntax near '@TableName'". (The input table does have a column called 'ColumnName&#39. How do you parametized an 'Insert Into' sql statement? I have tried a number of ways to no avail.
    Thanks,
    Judith


  3. #3
    Brian K. Guest

    correction

    There should be no parentheses:

    select @Str = 'Insert into ' + @TableNameD + '(ColumnName) Select #TempColumnNames.Name From #TempColumnNames'


    ------------
    Brian K. at 9/29/99 3:40:27 PM


    Here is the way to do it:

    (inside the procedure add this code

    declare @Str varchar(255)

    select @Str = ('Insert into ' + @TableNameD + '(ColumnName) Select #TempColumnNames.Name From #TempColumnNames)'

    EXec (@Str)


    Good Luck
    ------------
    Judith Farber Abraham at 9/29/99 12:43:32 PM

    I am writing a stored procedure:
    CREATE PROCEDURE rasp_FillDescrColumnNames
    @TableNameD varchar(50),
    @TableNameU varchar(50),
    @TableUID int
    --
    --
    AS
    ......

    Insert into @TableNameD(ColumnName)
    Select #TempColumnNames.Name
    From #TempColumnNames

    -----------------------------
    I get "incorrect syntax near '@TableName'". (The input table does have a column called 'ColumnName&#39. How do you parametized an 'Insert Into' sql statement? I have tried a number of ways to no avail.
    Thanks,
    Judith


Posting Permissions

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