Create SQL Insert Script with Values Gathered from Table

Create SQL INSERT Script with values gathered from table

You can do this with SSMS.

1 - Right-click your database in Object Explorer.

2 - Select Tasks/Generate Scripts...
3 - On the Set Scripting Options page, click the Advanced button and make sure Types of data to script is set to Data only.

The resulting script will have a USE DATABASE statement at the top. Change this to the database you would like to insert the data into.

Generate insert script for selected records?

If you are using the SQL Management Studio, you can right click your DB name and select
Tasks > Import/Export data and follow the wizard.

one of the steps is called "Specify Table Copy or Query" where there is an option to write a query to specify the data to transfer, so you can simply specify the following query:

select * from [Table] where Fk_CompanyId = 1

SQL Server, How to generate an `INSERT` statement for the rows in an existing table?

Here are the steps:-

  1. Right click on your database in SSMS
  2. Choose Tasks>Generate Scripts
  3. Select specific database objects - choose the table you want to
    script. Click next
  4. Select 'Save to new query window'. Click the 'Advanced button'
  5. Change 'Types of data to script' to 'Data only'.
  6. Click OK, Next, Next, Finish.

The query editor window should contain the script you need.

script data table content into insert statements using one command

You just want to dump the data in the table to a text file periodically? If so, what about using an SSIS package and scheduling it as a job.

insert data order by from another table

DECLARE @ProductTotals TABLE
(
srnum int,
PROGRESS_REPORT_BUDGETID int,
SUM_DESCRIPTION nvarchar(550),
RFP_ID int,
DESC_ID int,
GRAND_TOTAL decimal(18,3)
)
insert into @ProductTotals

SELECT row_number() over (order by (select NULL))as srnum,

PROGRESS_REPORT_BUDGETID,SUM_DESCRIPTION,

RFP_ID, DESC_ID, TOTAL_BUDGET from(
SELECT
PROGRESS_REPORT_BUDGETID,BS.SUM_DESCRIPTION,

RFP_ID, PB.DESC_ID, TOTAL_BUDGET

FROM tabl1 PB

INNER JOIN tabl_master BS ON PB.DESC_ID=BS.DESC_ID

where TOTAL_BUDGET <> 0
union all

select PROGRESS_REPORT_BUDGETID,BS.SUM_DESCRIPTION,

RFP_ID, PB.DESC_ID, TOTAL_BUDGET

FROM tabl1 PB

INNER JOIN tabl_master BS ON PB.DESC_ID=BS.DESC_ID

where TOTAL_BUDGET = 0
) A

   select * from @ProductTotals  

and my expected answer will be like this

enter image description here



Related Topics



Leave a reply



Submit