Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Database & SysAdmin
  3. Database
  4. sql statement

sql statement

Scheduled Pinned Locked Moved Database
databasehelpquestion
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    Sudee
    wrote on last edited by
    #1

    CREATE PROCEDURE pr_InsertDictTable @intID int, @vchrValue nvarchar(50), @vchrWesBarCode nvarchar(10), @vchrTableName varchar(20) AS declare @sql varchar(1000) set @sql = 'INSERT INTO ' + @vchrTableName + ' (Id, Name, PDACode) VALUES ( '+@intID+','+@vchrValue+','+@vchrWesBarCode+')' print @sql GO Any problem in this procedure? ====== You need a head to program. Cool, fast and sharp.

    A J 2 Replies Last reply
    0
    • S Sudee

      CREATE PROCEDURE pr_InsertDictTable @intID int, @vchrValue nvarchar(50), @vchrWesBarCode nvarchar(10), @vchrTableName varchar(20) AS declare @sql varchar(1000) set @sql = 'INSERT INTO ' + @vchrTableName + ' (Id, Name, PDACode) VALUES ( '+@intID+','+@vchrValue+','+@vchrWesBarCode+')' print @sql GO Any problem in this procedure? ====== You need a head to program. Cool, fast and sharp.

      A Offline
      A Offline
      Anonymous
      wrote on last edited by
      #2

      set @sql = 'INSERT INTO ' + @vchrTableName + ' (Id, Name, PDACode) VALUES ( '+@intID+','+@vchrValue+','+@vchrWesBarCode+')' -> set @sql = 'INSERT INTO ' + @vchrTableName + ' (Id, Name, PDACode) VALUES ( '+ CAST( @intID as varchar )+','+@vchrValue+','+@vchrWesBarCode+')'

      1 Reply Last reply
      0
      • S Sudee

        CREATE PROCEDURE pr_InsertDictTable @intID int, @vchrValue nvarchar(50), @vchrWesBarCode nvarchar(10), @vchrTableName varchar(20) AS declare @sql varchar(1000) set @sql = 'INSERT INTO ' + @vchrTableName + ' (Id, Name, PDACode) VALUES ( '+@intID+','+@vchrValue+','+@vchrWesBarCode+')' print @sql GO Any problem in this procedure? ====== You need a head to program. Cool, fast and sharp.

        J Offline
        J Offline
        Jon Hulatt
        wrote on last edited by
        #3

        Yes, plenty. 1. It's pointless. All you're doing is printing a string. Why not just generate the string at the caller? 2. variable @sql is not needed. you could just "print 'insert into ... " 3. It won't work. You need to CONVERT(varchar(10),@intid) before you can use it as a varchar. 4. You're mixing nvarchar and varchar. and implicitly casting nvarchar to varchar, thus negating the whole point of using nvarchar in the first place. 5. I think hungarian notation in a database is evil. 6. The main point of stored procedures is that they're compiled and hence more efficient. You're not leveraging that efficiency at all here. jon

        #include <beer.h>

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups