SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Help me for insert on query please


Help me for insert on query please

Author
Message
Nardig
Nardig
Forum Newbie
Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)

Group: General Forum Members
Points: 4 Visits: 9
how can i insert more that one row with query on a singel table
Lynn Pettis
Lynn Pettis
SSC Guru
SSC Guru (98K reputation)SSC Guru (98K reputation)SSC Guru (98K reputation)SSC Guru (98K reputation)SSC Guru (98K reputation)SSC Guru (98K reputation)SSC Guru (98K reputation)SSC Guru (98K reputation)

Group: General Forum Members
Points: 98152 Visits: 38996
I have no idea. You haven't provided us with anything to work with here.

Cool
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)
Nardig
Nardig
Forum Newbie
Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)

Group: General Forum Members
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
Lynn Pettis
Lynn Pettis
SSC Guru
SSC Guru (98K reputation)SSC Guru (98K reputation)SSC Guru (98K reputation)SSC Guru (98K reputation)SSC Guru (98K reputation)SSC Guru (98K reputation)SSC Guru (98K reputation)SSC Guru (98K reputation)

Group: General Forum Members
Points: 98152 Visits: 38996
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?

Cool
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)
Nardig
Nardig
Forum Newbie
Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)

Group: General Forum Members
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
WayneS
WayneS
SSC-Insane
SSC-Insane (22K reputation)SSC-Insane (22K reputation)SSC-Insane (22K reputation)SSC-Insane (22K reputation)SSC-Insane (22K reputation)SSC-Insane (22K reputation)SSC-Insane (22K reputation)SSC-Insane (22K reputation)

Group: General Forum Members
Points: 22312 Visits: 10657
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
Author - SQL Server T-SQL Recipes
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

Vinit Srivastava
Vinit Srivastava
SSC Veteran
SSC Veteran (283 reputation)SSC Veteran (283 reputation)SSC Veteran (283 reputation)SSC Veteran (283 reputation)SSC Veteran (283 reputation)SSC Veteran (283 reputation)SSC Veteran (283 reputation)SSC Veteran (283 reputation)

Group: General Forum Members
Points: 283 Visits: 178
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
Lynn Pettis
Lynn Pettis
SSC Guru
SSC Guru (98K reputation)SSC Guru (98K reputation)SSC Guru (98K reputation)SSC Guru (98K reputation)SSC Guru (98K reputation)SSC Guru (98K reputation)SSC Guru (98K reputation)SSC Guru (98K reputation)

Group: General Forum Members
Points: 98152 Visits: 38996
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;



Cool
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)
Lynn Pettis
Lynn Pettis
SSC Guru
SSC Guru (98K reputation)SSC Guru (98K reputation)SSC Guru (98K reputation)SSC Guru (98K reputation)SSC Guru (98K reputation)SSC Guru (98K reputation)SSC Guru (98K reputation)SSC Guru (98K reputation)

Group: General Forum Members
Points: 98152 Visits: 38996
Okay, my post above looks strange to me.

Cool
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)
Vinit Srivastava
Vinit Srivastava
SSC Veteran
SSC Veteran (283 reputation)SSC Veteran (283 reputation)SSC Veteran (283 reputation)SSC Veteran (283 reputation)SSC Veteran (283 reputation)SSC Veteran (283 reputation)SSC Veteran (283 reputation)SSC Veteran (283 reputation)

Group: General Forum Members
Points: 283 Visits: 178
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
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search