• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 258
  • Last Modified:

Generate Insert SQL Statement

I want a script to generate insert sql statement form a table .The one that i already have with me (http://www.codeproject.com/KB/database/InsertGeneratorPack.aspx)
isnt working if the column contains single quotes or comma.
0
venk_r
Asked:
venk_r
  • 4
1 Solution
 
EyalCommented:
replace this...

BEGIN
IF @dataType in ('varchar','char','nchar','nvarchar')
BEGIN
    SET @stringData=@stringData+'''''''''+
            isnull('+@colName+','''')+'''''',''+'
END

with this...

BEGIN
IF @dataType in ('varchar','char','nchar','nvarchar')
BEGIN
    SET @stringData=@stringData+'''''''''+
            replace(isnull('+@colName+',''''),''''','''''')+'''''',''+'
END
0
 
venk_rAuthor Commented:
I think its still missing somerthing.Its giving me syntax error
0
 
venk_rAuthor Commented:
Actually  Im able to get the script generated from the Managament studio itself by using generate script task,Thanks
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
EvilPostItCommented:
0
 
venk_rAuthor Commented:
Im able to do it from SSMS itself.
0
 
venk_rAuthor Commented:
Im able to generate the insert sql from SSMS itself.
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now