I would like to export a ad hoc Select query result sets from SQL Server to be exported directly as Insert Statements.
I would love to see a Save As option "Insert.." along with the other current available options (csv, txt) when you right-click in SSMS. I am not exporting from an existing physical table and I have no permissions to create new tables so the options to script physical tables are not an option for me.
I have to script either from temporary tables or from the result set in the query window.
Right now I can export to csv and then import that file into another table but that's time consuming for repetitive work.
The tool has to create proper Inserts and understand the data types when it creates values for NULL values.
Personally, I would just write a select against the table and generate the inserts myself. Piece of cake.
For example:
SELECT 'insert into [pubs].[dbo].[authors](
[au_id],
[au_lname],
[au_fname],
[phone],
[address],
[city],
[state],
[zip],
[contract])
values( ''' +
[au_id] + ''', ''' +
[au_lname] + ''', ''' +
[au_fname] + ''', ''' +
[phone] + ''', ''' +
[address] + ''', ''' +
[city] + ''', ''' +
[state] + ''', ''' +
[zip] + ''', ' +
cast([contract] as nvarchar) + ');'
FROM [pubs].[dbo].[authors]
will produce
insert into [pubs].[dbo].[authors](
[au_id],
[au_lname],
[au_fname],
[phone],
[address],
[city],
[state],
[zip],
[contract])
values( '172-32-1176', 'White', 'Johnson', '408 496-7223', '10932 Bigge Rd.', 'Menlo Park', 'CA', '94025', 1);
insert into [pubs].[dbo].[authors](
[au_id],
[au_lname],
[au_fname],
[phone],
[address],
[city],
[state],
[zip],
[contract])
values( '213-46-8915', 'Green', 'Marjorie', '415 986-7020', '309 63rd St. #411', 'Oakland', 'CA', '94618', 1);
... etc ...
A couple pitfalls:
take a look at the SSMS Tools Pack add in for SSMS which allows you to do just what you need.
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