Here is another method, which may be easier than installing plugins or external tools in some situations:
- Do a
select [whatever you need]
INTO temp.table_name
from [... etc ...]
.
- Right-click on the database in the Object Explorer => Tasks => Generate Scripts
- Select
temp.table_name
in the "Choose Objects" screen, click Next.
- In the "Specify how scripts should be saved" screen:
- Click Advanced, find the "Types of data to Script" property, select "Data only", close the advanced properties.
- Select "Save to new query window" (unless you have thousands of records).
- Click Next, wait for the job to complete, observe the resulting
INSERT
statements appear in a new query window.
- Use Find & Replace to change all
[temp.table_name]
to [your_table_name]
.
drop table [temp.table_name]
.