What you want to see on DotNetFunda.com ?
DotNetFunda.Com Logo
Twitter TwitterLinkedIn
YouTubeGoogle
 Online : 3970 |  Welcome, Guest!   Register  Login
 Home > Coding Horrors > SQL Server > Query for Getting insert scripts of the Table's Data ...
Arunjith

Query for Getting insert scripts of the Table's Data

 Coding Horror posted by: Arunjith | Posted on: 6/12/2012 | Category: SQL Server | Views: 2045 | Level: Starter | Status: [Member] | Points: 75 | Alert Moderator   




SELECT *, 'INSERT INTO db_name.[dbo].tbl_name VALUES('''+  CAST([column_1] AS VARCHAR)  + ''', '''+ CAST(column_2 AS VARCHAR)+ ''', '''+ CAST(column_3 AS VARCHAR)+ ''')' FROM db_name.[dbo].tbl_name



Found interesting? Add this to:


About Arunjith P.S

Experience:0 year(s)
Home page:http://www.dotnetfunda.com
Member since:Tuesday, June 12, 2012
Level:Starter
Status: [Member]
Biography:
 Responses
Muhsinathk
Posted by: Muhsinathk | Posted on: 6/12/2012 | Level: Bronze | Status: [Member] | Points: 15 | Alert Moderator 

I cant execute well

i am getting error that

Invalid object name 'Person.dbo.Test'.



Muhsinathk
Posted by: Muhsinathk | Posted on: 6/12/2012 | Level: Bronze | Status: [Member] | Points: 15 | Alert Moderator 

Yess..got it..
Thank you

Montysahu
Posted by: Montysahu | Posted on: 6/22/2012 | Level: Starter | Status: [Member] | Points: 15 | Alert Moderator 

Hi,
I am Test this script and litte bit change..

SELECT *, 'INSERT INTO TestDB.[dbo].Employee VALUES('''+ CAST([EmpID] AS VARCHAR) + ''', '''+ CAST(EmpName AS VARCHAR)+ ''', '''+ CAST(ManagerID AS VARCHAR)+ ''')' as InsertQuery FROM TestDB.[dbo].Employee

Why you convet the each columns datatype to varchar,convet to actual datatype..

Anyway...this is working fine.... if you want something more then please replay me.


Srilu.Nayini577
Posted by: Srilu.Nayini577 | Posted on: 8/6/2012 | Level: Starter | Status: [Member] | Points: 15 | Alert Moderator 

Hi,
I test this working fine also

Syntax:
---------
SELECT *, 'INSERT INTO db_name.[dbo].tbl_name VALUES('''+ CAST([column_1] AS VARCHAR) + ''', '''+ CAST(column_2 AS VARCHAR)+ ''', '''+ CAST(column_3 AS VARCHAR)+ ''')' FROM db_name.[dbo].tbl_name

Example:
-----------
SELECT *, 'INSERT INTO Employee.[dbo].Employee1 VALUES('''+ CAST([EmpId] AS VARCHAR) + ''', '''+ CAST(Name AS VARCHAR)+ ''','''+ CAST(Designation AS VARCHAR)+ ''','''+ CAST(Address AS VARCHAR)+ ''')' FROM Employee.[dbo].Employee


Thank you,




SRILATHA
.Net Developer

>> Write Response - Respond to this post and get points

More Coding Horrors

About Us | Contact Us | The Team | Advertise | Software Development | Write for us | Testimonials | Privacy Policy | Terms of Use | Link Exchange | Members | Go Top
General Notice: If you find plagiarised (copied) contents on this page, please let us know the original source along with your correct email id (to communicate) for further action.
Copyright © DotNetFunda.Com. All Rights Reserved. Copying or mimicking the site design and layout is prohibited. Logos, company names used here if any are only for reference purposes and they may be respective owner's right or trademarks. | 5/25/2013 10:54:51 PM