how to get table name as input parameter in SQL procedure

  • Hi

    I am using follwing query for creating and inserting a table through a procedure..

    Alter PROCEDURE CreateInsertTable

    @TableName varchar (500),

    @InputTable varchar (1000)

    AS

    BEGIN

    declare @sql varchar(4000)

    select @sql = ' CREATE TABLE ' + @TableName + '

    (RecordNo BIGINT IDENTITY(1,1),

    GrpAddressID BIGINT,

    OccType1_CommaSeperated VARCHAR(1000) )'

    exec (@sql)

    declare @ssql nvarchar(4000)

    select @ssql = 'INSERT INTO ' + @TableName + ' (GrpAddressID)

    SELECT GrpAddressID

    FROM '+ @InputTable +'

    GROUP BY GrpAddressID

    ORDER BY GrpAddressID'

    exec (@ssql)

    END

    Execute statement :

    EXEC CreateTable @TableName= 'CommaSEperated3' ,@InputTable='AtulTest'

    Its Showing err message :

    Msg 8144, Level 16, State 2, Procedure CreateTable, Line 0

    Procedure or function CreateTable has too many arguments specified.

    Please help to resolve it.

    Thanks

    Atul

  • Execute statement :

    EXEC CreateTable TableName= 'CommaSEperated3' ,@InputTable='AtulTest'

    Please read your question again by yourself. TableName should be written as @TableName. Also your procedure name is different in definition.

  • Sorry...That was my mistake...Actually name of procedure was incorrect...NOw its running fine..

    Thanks

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply