I have SQL Server 2008
, SQL Server Management Studio.
I need to select data from Table1
in database1. Then I have to edit some values in the results and insert values into Table1
in database2.
Or let me put it other way.
How can I convert the data in one table into insert script
.
Convert a database query (or stored procedure) result, which may contain multiple data sets, into a sql select script. Convert-QueryDataToSQL -ServerInstance Server1 -Database Database -Query 'SELECT * FROM [Database]. [schema].
Your select statement result set has been inserted into the table ( [tbl_Department_Sample]). Now, you just need to generate the script (data only) of the table ( [tbl_Department_Sample]) using Generate Script feature in SQL Server 2012 and above.
You can Choose 'Result to File' option in SSMS and export your select result to file and make your changes in result file and finally using BCP - Bulk copy you can insert in table 1 in database 2. Hope it will help. I had a similar problem, but I needed to be able to create an INSERT statement from a query (with filters etc.)
There are multiple ways via SQL Server Management Studio (SSMS) or dynamic SQL that we can generate a SELECT script that includes both the column name and the column value. This is useful to port data to other databases or to just have the data in a script that can be used to repopulate a table as needed.
Here is another method, which may be easier than installing plugins or external tools in some situations:
select [whatever you need]
INTO temp.table_name
from [... etc ...]
.temp.table_name
in the "Choose Objects" screen, click Next.INSERT
statements appear in a new query window.[temp.table_name]
to [your_table_name]
.drop table [temp.table_name]
.In SSMS:
Right click on the database > Tasks > Generate Scripts
Next
Select "Select specific database objects" and check the table you want scripted, Next
Click Advanced >
in the list of options, scroll down to the bottom and look for the "Types of data to script" and change it to "Data Only" > OK
Select "Save to new query window" > Next > Next > Finish
All 180 rows now written as 180 insert statements!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With