Results 1 to 4 of 4
  1. #1
    Join Date
    Apr 2008
    Posts
    1

    Unanswered: Problem With Insert Into Table Whose Name Is Supplied Dynamically

    I am try to build a Stored procedure to insert into a table whose name is contain in variable @tname, other field are just variable to supply value to table fields,i have implement simple type of SP for "SELECT" AND "CREATE" ,but this procedure does not work, please help me



    CREATE proc insert_mess
    @tname nvarchar(50),
    @mass nvarchar(250),
    @to_id int,
    @form_id int
    as
    exec ('insert into ['+ @tname +'] ( [message],to_id,form_id)
    values ('+ @mass +',' +@to_id + ','+@form_id +') ')

  2. #2
    Join Date
    Nov 2002
    Posts
    272
    Do you get an error message?

  3. #3
    Join Date
    Feb 2004
    Location
    Bangalore, India
    Posts
    250
    try this..

    insert into ['+ @tname +'] ( [message],to_id,form_id) values ('+ '''' + @mass + '''' + ',' + convert(varchar,@to_id) + ',' + convert(varchar,@form_id) +') '
    Cheers....

    baburajv

  4. #4
    Join Date
    Apr 2008
    Posts
    1
    try:
    CREATE proc insert_mess
    @tname sysname,
    @mass nvarchar(250),
    @to_id int,
    @form_id int
    as
    exec ('insert into ['+ @tname +'] ( [message],to_id,form_id)
    values ('+ @mass +',' +@to_id + ','+@form_id +') ')

Posting Permissions

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