Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 How to generate the insert statement

Author  Topic 

Idyana
Yak Posting Veteran

96 Posts

Posted - 2011-07-25 : 08:45:48
I've table as following,
CREATE TABLE [dbo].[paymentType](
[idx] [int] IDENTITY(1,1) NOT NULL,
 [varchar](20) NOT NULL,
[descrp] [varchar](100) NOT NULL,
CONSTRAINT [PK_paymentType] PRIMARY KEY CLUSTERED
(
[idx] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]


My data as following,
[code]insert into paymentType values('csh','cash');
insert into paymentType values('chq','cheque');
insert into paymentType values('cc','credit card');
insert into paymentType values('bk','bankard');


Let's say my paymentType table have a lot of data. How to generate the insert statement using SQL Server tools? Or have another technique?

need help

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2011-07-25 : 08:53:31
Follow this post
http://blog.sqlauthority.com/2009/07/29/sql-server-2008-copy-database-with-data-generate-t-sql-for-inserting-data-from-one-table-to-another-table/

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

sharona
Yak Posting Veteran

75 Posts

Posted - 2011-07-25 : 09:27:23
what is do is i use and xls spreadsheet
DATA BEING INSERTED IN MY FIRST FEW COLUMNS
CCC 21 21500 0 0.00 20100831

INSERT STATEMENT IN THE COLUMN NEXT TO THE DATA
insert into dbo.INVENTORY_BEG_BAL_STYLE_JULY2010 (division,season,style, BEG_BAL,cost,me_date)values

STATIC VALUES TO USE IN THE CONCATENATE STATEMENT
( ', ' ' , )

MY CONCATENATE STATMENT
=CONCATENATE(G1,H1,J1,A1,I1,J1,B1,I1,C1,L1,D1,L1,E1,L1,F1,M1)

RESULTS TO BE COPIES TO THE SCRIPT TO INSERT

insert into dbo.INVENTORY_BEG_BAL_STYLE_JULY2010 (division,season,style, BEG_BAL,cost,me_date)values('CCC','21',21500,0,0,20100831)

I paste my data to be inserted in the first few columns
and then ensure my concatenate is picking up the columns correctly,
i then copy the result vlaues into my script. big time saver
Go to Top of Page
   

- Advertisement -