Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

Help me for insert on query please Expand / Collapse
Author
Message
Posted Tuesday, June 30, 2009 4:05 PM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Friday, February 17, 2012 1:43 PM
Points: 4, Visits: 9
how can i insert more that one row with query on a singel table
Post #744959
Posted Tuesday, June 30, 2009 4:13 PM


SSC-Insane

SSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-Insane

Group: General Forum Members
Last Login: Today @ 2:42 PM
Points: 23,042, Visits: 31,565
I have no idea. You haven't provided us with anything to work with here.



Lynn Pettis

For better assistance in answering your questions, click here
For tips to get better help with Performance Problems, click here
For Running Totals and its variations, click here or when working with partitioned tables
For more about Tally Tables, click here
For more about Cross Tabs and Pivots, click here and here
Managing Transaction Logs

SQL Musings from the Desert Fountain Valley SQL (My Mirror Blog)
Post #744961
Posted Tuesday, June 30, 2009 4:41 PM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Friday, February 17, 2012 1:43 PM
Points: 4, Visits: 9
ok i have one table with MemberID, Name, Surname and City and information for inserted on this table and i have on text file for example 1001, John, Smith, Washington another member is 1002, Nick, Dagle, London etc etc. I request to insert at the same time on this table.

for example


INSERT INTO TblMember
(MemberID, Name, Surname, City)
VALUES (1001,John,Smith,Washington;
1002, Nick, Smith, London
1003,....,.....,.....)

I hope you know what I think now

thanks
Post #744973
Posted Tuesday, June 30, 2009 4:51 PM


SSC-Insane

SSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-Insane

Group: General Forum Members
Last Login: Today @ 2:42 PM
Points: 23,042, Visits: 31,565
Nardig (6/30/2009)
ok i have one table with MemberID, Name, Surname and City and information for inserted on this table and i have on text file for example 1001, John, Smith, Washington another member is 1002, Nick, Dagle, London etc etc. I request to insert at the same time on this table.

for example


INSERT INTO TblMember
(MemberID, Name, Surname, City)
VALUES (1001,John,Smith,Washington;
1002, Nick, Smith, London
1003,....,.....,.....)

I hope you know what I think now

thanks


You want to import a text file into a table? Each row of the text file contains a record with MemberId, FirstName, LastName, City?

What is the delimiter between columns? Rows? Are the string values delimited and if so with what, double quotes?



Lynn Pettis

For better assistance in answering your questions, click here
For tips to get better help with Performance Problems, click here
For Running Totals and its variations, click here or when working with partitioned tables
For more about Tally Tables, click here
For more about Cross Tabs and Pivots, click here and here
Managing Transaction Logs

SQL Musings from the Desert Fountain Valley SQL (My Mirror Blog)
Post #744983
Posted Tuesday, June 30, 2009 5:25 PM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Friday, February 17, 2012 1:43 PM
Points: 4, Visits: 9
Yes the text file looks like this

1,'John','Smith','Washington'
2,'Nick','Smith','London'
3,'blabla','blabla','blaa'
.
.
.
this text contains 1200 records

Post #744995
Posted Tuesday, June 30, 2009 9:43 PM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Today @ 3:04 PM
Points: 6,582, Visits: 8,861
Nardig (6/30/2009)
Yes the text file looks like this

1,'John','Smith','Washington'
2,'Nick','Smith','London'
3,'blabla','blabla','blaa'
.
.
.
this text contains 1200 records


Check out Books-Online (BOL) for "BULK INSERT". If your destination table has additional columns, you may need a format file (see "BCP" in BOL for how to create one). Since your field terminator isn't a tab, you'll need to specify that in the BULK INSERT command.


Wayne
Microsoft Certified Master: SQL Server 2008
If you can't explain to another person how the code that you're copying from the internet works, then DON'T USE IT on a production system! After all, you will be the one supporting it!
Links: For better assistance in answering your questions, How to ask a question, Performance Problems, Common date/time routines,
CROSS-TABS and PIVOT tables Part 1 & Part 2, Using APPLY Part 1 & Part 2, Splitting Delimited Strings
Post #745052
Posted Tuesday, June 30, 2009 10:56 PM
SSC Veteran

SSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC Veteran

Group: General Forum Members
Last Login: Wednesday, May 21, 2014 11:13 PM
Points: 269, Visits: 170
Hi Friend ,
Fallow below steps .
1. Create one function with three parameter
String( RowData),Delimeter,Position that return the data for the passed position from the passed rowdata.
Create Function [Functin Name]
(
@Rowdata VARCHAR(8000),
@Delimeter CHAR(1),
@Position INT
)
RETURNS VARCHAR(300)
AS
BEGIN
--Write here code for find the data from the passed Rowdata
END

2. Use bulk insert command and store the data in a #Temp table( Having only one column with size varchar(4000) .
3. After completing above steps in one select statement all the data from the text file will be inserted in your table . For Ex.

Insert into [Table Name]
Select Function(Rowdata,delimeter,position) from #TempTable


Thanks
Vinit Srivastava
Post #745073
Posted Tuesday, June 30, 2009 11:11 PM


SSC-Insane

SSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-Insane

Group: General Forum Members
Last Login: Today @ 2:42 PM
Points: 23,042, Visits: 31,565
Sample code for you to play with. You will need to put the data into a text file, and be sure to modify the line where I have the code looking for the file to point to where you put it.

/*
Sample data from file CustInfo.txt:
1,"John","Smith","Washington"
2,"Nick","Smith","London"
3,"blabla","blabla","blaa"
*/

create table dbo.TestTable (
MemberID int,
FirstName varchar(30),
LastName varchar(30),
City varchar(30)
);

bulk insert dbo.TestTable
from 'C:\Databases\ImportData\CustInfo.txt'
with (
codepage = 'RAW',
datafiletype = 'char',
fieldterminator = ',',
rowterminator = ''
);

update dbo.TestTable set
FirstName = replace(FirstName,'"',''),
LastName = replace(LastName,'"',''),
City = replace(City,'"','');

select
*
from
dbo.TestTable;

drop table dbo.TestTable;




Lynn Pettis

For better assistance in answering your questions, click here
For tips to get better help with Performance Problems, click here
For Running Totals and its variations, click here or when working with partitioned tables
For more about Tally Tables, click here
For more about Cross Tabs and Pivots, click here and here
Managing Transaction Logs

SQL Musings from the Desert Fountain Valley SQL (My Mirror Blog)
Post #745082
Posted Tuesday, June 30, 2009 11:13 PM


SSC-Insane

SSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-Insane

Group: General Forum Members
Last Login: Today @ 2:42 PM
Points: 23,042, Visits: 31,565
Okay, my post above looks strange to me.



Lynn Pettis

For better assistance in answering your questions, click here
For tips to get better help with Performance Problems, click here
For Running Totals and its variations, click here or when working with partitioned tables
For more about Tally Tables, click here
For more about Cross Tabs and Pivots, click here and here
Managing Transaction Logs

SQL Musings from the Desert Fountain Valley SQL (My Mirror Blog)
Post #745084
Posted Friday, July 3, 2009 5:42 AM
SSC Veteran

SSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC Veteran

Group: General Forum Members
Last Login: Wednesday, May 21, 2014 11:13 PM
Points: 269, Visits: 170
Sorry Friend ,
In my last post i think i have given you the steps for inserting data from any file into any table .
But now i realise that that is worthless for you . Now for your post

how can i insert more that one row with query
so Now use this simple query .
Insert into table [Table Name]
Select [Col1,Col2,Col3,Col4....etc] from [Table Name]
Use This Query
Post #746935
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse