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:-
- Right click on your database in SSMS
- Choose Tasks>Generate Scripts
- Select specific database objects - choose the table you want to
script. Click next - Select 'Save to new query window'. Click the 'Advanced button'
- Change 'Types of data to script' to 'Data only'.
- 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
What Are Indexes and How to Use Them to Optimize Queries in My Database
How to Exclude Records with Certain Values in SQL Select
SQL Server 2005 Using Dateadd to Add a Day to a Date
Limit Results from Joined Table to One Row
How to Escape Ampersand in Toad
#1146 - Table 'Phpmyadmin.Pma_Tracking' Doesn't Exist
Creating New User/Login in SQL Azure
Executing a Dynamic SQL Statement into a Sys_Refcursor
T-SQL - Group by with Like - Is This Possible
Select Top N Record from Each Group SQLite
How to Find All Rows with a Null Value in Any Column Using Postgresql
How to Keep the Order Using Select Where In()
What Is the Data Type for Unix_Timestamp (Mysql)
SQL Select Max(Date) and Corresponding Value
Sql: Search for a String in Every Varchar Column in a Database
Pl/SQL Performance Tuning for Like '%...%' Wildcard Queries
Why Is Selecting Specified Columns, and All, Wrong in Oracle SQL