dbTalk Databases Forums  

Importing CSV file using store procedure

microsoft.public.sqlserver.dts microsoft.public.sqlserver.dts


Discuss Importing CSV file using store procedure in the microsoft.public.sqlserver.dts forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Ashish Kanoongo
 
Posts: n/a

Default Importing CSV file using store procedure - 06-05-2004 , 07:37 AM






I would like to create DTS for Importing from CSV using store procedure, in which I would like to update fields conditionally.

Anyone can help in this matter or let me know url/tutorial on this.

Thanks in advance


---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.699 / Virus Database: 456 - Release Date: 06/04/2004

Reply With Quote
  #2  
Old   
Allan Mitchell
 
Posts: n/a

Default Re: Importing CSV file using store procedure - 06-05-2004 , 07:58 AM






No real need here for DTS other then using it is a workflow engine.

Look up BULK INSERT in BOL.

Stage the data into a working entity and then use TSQL Statements to do your
UPDATEs

--
--

Allan Mitchell MCSE,MCDBA, (Microsoft SQL Server MVP)
www.SQLDTS.com - The site for all your DTS needs.
I support PASS - the definitive, global community
for SQL Server professionals - http://www.sqlpass.org


"Ashish Kanoongo" <ashishk (AT) armour (DOT) com> wrote

I would like to create DTS for Importing from CSV using store procedure, in
which I would like to update fields conditionally.

Anyone can help in this matter or let me know url/tutorial on this.

Thanks in advance


---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.699 / Virus Database: 456 - Release Date: 06/04/2004



Reply With Quote
  #3  
Old   
Ashish Kanoongo
 
Posts: n/a

Default Re: Importing CSV file using store procedure - 06-07-2004 , 11:38 PM



I have following logic , how do use this logic in DTS. Here is my logic

*------------------------------------------------
Dim reccount As Double
'On Error Resume Next
Const adOpenStatic = 3
Const adLockOptimistic = 3
Const adCmdText = &H1
Set objConnection = CreateObject("ADODB.Connection")
Set objConn = CreateObject("ADODB.Connection")
Set objRecordset = CreateObject("ADODB.Recordset")

strPathtoTextFile = "C:\"

objConn.Open ("Provider=SQLOLEDB.1;Persist Security Info=False;User
ID=sa;Initial Catalog=stocks;Data Source=webserver1")

objConnection.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & strPathtoTextFile & ";" & _
"Extended Properties=""text;HDR=YES;FMT=FixedLength"""

objRecordset.Open "SELECT * FROM accounts.csv", _
objConnection, adOpenStatic, adLockOptimistic, adCmdText

Do Until objRecordset.EOF
strCSV = "update accounts set closed = 0 where accountid=" &
objRecordset.Fields.Item("AccountID")
objConn.Execute strCSV
objRecordset.MoveNext
Loop
objRecordset.Close
objRecordset.Open "select count(*) from accounts where closed=0", objConn
MsgBox objRecordset(0)

*-------------------------------
"Allan Mitchell" <allan (AT) no-spam (DOT) sqldts.com> wrote

Quote:
No real need here for DTS other then using it is a workflow engine.

Look up BULK INSERT in BOL.

Stage the data into a working entity and then use TSQL Statements to do
your
UPDATEs

--
--

Allan Mitchell MCSE,MCDBA, (Microsoft SQL Server MVP)
www.SQLDTS.com - The site for all your DTS needs.
I support PASS - the definitive, global community
for SQL Server professionals - http://www.sqlpass.org


"Ashish Kanoongo" <ashishk (AT) armour (DOT) com> wrote in message
news:ewhpWmvSEHA.2944 (AT) tk2msftngp13 (DOT) phx.gbl...
I would like to create DTS for Importing from CSV using store procedure,
in
which I would like to update fields conditionally.

Anyone can help in this matter or let me know url/tutorial on this.

Thanks in advance


---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.699 / Virus Database: 456 - Release Date: 06/04/2004



---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.700 / Virus Database: 457 - Release Date: 06/06/2004




Reply With Quote
  #4  
Old   
Allan Mitchell
 
Posts: n/a

Default Re: Importing CSV file using store procedure - 06-08-2004 , 03:14 AM



OK

So you want to update a table in SQL Server from values in a text field. I
ALWAYS import text files into staging tables if I am going to do something
like this and then use TSQL to do the sexy bits

--

----------------------------

Allan Mitchell MCSE,MCDBA, (Microsoft SQL Server MVP)
www.SQLDTS.com - The site for all your DTS needs.
I support PASS - the definitive, global community
for SQL Server professionals - http://www.sqlpass.org


"Ashish Kanoongo" <ashishk (AT) armour (DOT) com> wrote

Quote:
I have following logic , how do use this logic in DTS. Here is my logic

*------------------------------------------------
Dim reccount As Double
'On Error Resume Next
Const adOpenStatic = 3
Const adLockOptimistic = 3
Const adCmdText = &H1
Set objConnection = CreateObject("ADODB.Connection")
Set objConn = CreateObject("ADODB.Connection")
Set objRecordset = CreateObject("ADODB.Recordset")

strPathtoTextFile = "C:\"

objConn.Open ("Provider=SQLOLEDB.1;Persist Security Info=False;User
ID=sa;Initial Catalog=stocks;Data Source=webserver1")

objConnection.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & strPathtoTextFile & ";" & _
"Extended Properties=""text;HDR=YES;FMT=FixedLength"""

objRecordset.Open "SELECT * FROM accounts.csv", _
objConnection, adOpenStatic, adLockOptimistic, adCmdText

Do Until objRecordset.EOF
strCSV = "update accounts set closed = 0 where accountid=" &
objRecordset.Fields.Item("AccountID")
objConn.Execute strCSV
objRecordset.MoveNext
Loop
objRecordset.Close
objRecordset.Open "select count(*) from accounts where closed=0", objConn
MsgBox objRecordset(0)

*-------------------------------
"Allan Mitchell" <allan (AT) no-spam (DOT) sqldts.com> wrote in message
news:OJXDQwvSEHA.2480 (AT) TK2MSFTNGP10 (DOT) phx.gbl...
No real need here for DTS other then using it is a workflow engine.

Look up BULK INSERT in BOL.

Stage the data into a working entity and then use TSQL Statements to do
your
UPDATEs

--
--

Allan Mitchell MCSE,MCDBA, (Microsoft SQL Server MVP)
www.SQLDTS.com - The site for all your DTS needs.
I support PASS - the definitive, global community
for SQL Server professionals - http://www.sqlpass.org


"Ashish Kanoongo" <ashishk (AT) armour (DOT) com> wrote in message
news:ewhpWmvSEHA.2944 (AT) tk2msftngp13 (DOT) phx.gbl...
I would like to create DTS for Importing from CSV using store procedure,
in
which I would like to update fields conditionally.

Anyone can help in this matter or let me know url/tutorial on this.

Thanks in advance


---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.699 / Virus Database: 456 - Release Date: 06/04/2004




---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.700 / Virus Database: 457 - Release Date: 06/06/2004





Reply With Quote
  #5  
Old   
John Bell
 
Posts: n/a

Default Re: Importing CSV file using store procedure - 06-08-2004 , 06:48 AM



Hi

This is untested but you may want to try opening the datasource within the
update statement therefore there would be no need to step through the record
set.

strCSV = "update a set closed = 0
from accounts a JOIN
OpenDataSource( 'Microsoft.Jet.OLEDB.4.0',
'Data Source=""" & strPathtoTextFile & """;" & _
"Extended
Properties=""text;HDR=YES;FMT=FixedLength""')...ac counts.csv c
ON a.accountid= C.accountid"

objConn.Execute strCSV

John

"Ashish Kanoongo" <ashishk (AT) armour (DOT) com> wrote

Quote:
I have following logic , how do use this logic in DTS. Here is my logic

*------------------------------------------------
Dim reccount As Double
'On Error Resume Next
Const adOpenStatic = 3
Const adLockOptimistic = 3
Const adCmdText = &H1
Set objConnection = CreateObject("ADODB.Connection")
Set objConn = CreateObject("ADODB.Connection")
Set objRecordset = CreateObject("ADODB.Recordset")

strPathtoTextFile = "C:\"

objConn.Open ("Provider=SQLOLEDB.1;Persist Security Info=False;User
ID=sa;Initial Catalog=stocks;Data Source=webserver1")

objConnection.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & strPathtoTextFile & ";" & _
"Extended Properties=""text;HDR=YES;FMT=FixedLength"""

objRecordset.Open "SELECT * FROM accounts.csv", _
objConnection, adOpenStatic, adLockOptimistic, adCmdText

Do Until objRecordset.EOF
strCSV = "update accounts set closed = 0 where accountid=" &
objRecordset.Fields.Item("AccountID")
objConn.Execute strCSV
objRecordset.MoveNext
Loop
objRecordset.Close
objRecordset.Open "select count(*) from accounts where closed=0", objConn
MsgBox objRecordset(0)

*-------------------------------
"Allan Mitchell" <allan (AT) no-spam (DOT) sqldts.com> wrote in message
news:OJXDQwvSEHA.2480 (AT) TK2MSFTNGP10 (DOT) phx.gbl...
No real need here for DTS other then using it is a workflow engine.

Look up BULK INSERT in BOL.

Stage the data into a working entity and then use TSQL Statements to do
your
UPDATEs

--
--

Allan Mitchell MCSE,MCDBA, (Microsoft SQL Server MVP)
www.SQLDTS.com - The site for all your DTS needs.
I support PASS - the definitive, global community
for SQL Server professionals - http://www.sqlpass.org


"Ashish Kanoongo" <ashishk (AT) armour (DOT) com> wrote in message
news:ewhpWmvSEHA.2944 (AT) tk2msftngp13 (DOT) phx.gbl...
I would like to create DTS for Importing from CSV using store procedure,
in
which I would like to update fields conditionally.

Anyone can help in this matter or let me know url/tutorial on this.

Thanks in advance


---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.699 / Virus Database: 456 - Release Date: 06/04/2004




---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.700 / Virus Database: 457 - Release Date: 06/06/2004





Reply With Quote
  #6  
Old   
Ashish Kanoongo
 
Posts: n/a

Default Re: Importing CSV file using store procedure - 06-08-2004 , 07:08 AM



Thanks john. But I wouldlike to use this in DTS and I am new to DTS, so I am
looking for a guidance for all sql Gurus.
"John Bell" <jbellnewsposts (AT) hotmail (DOT) com> wrote

Quote:
Hi

This is untested but you may want to try opening the datasource within the
update statement therefore there would be no need to step through the
record
set.

strCSV = "update a set closed = 0
from accounts a JOIN
OpenDataSource( 'Microsoft.Jet.OLEDB.4.0',
'Data Source=""" & strPathtoTextFile & """;" & _
"Extended
Properties=""text;HDR=YES;FMT=FixedLength""')...ac counts.csv c
ON a.accountid= C.accountid"

objConn.Execute strCSV

John

"Ashish Kanoongo" <ashishk (AT) armour (DOT) com> wrote in message
news:OMvXzIRTEHA.2324 (AT) TK2MSFTNGP10 (DOT) phx.gbl...
I have following logic , how do use this logic in DTS. Here is my logic

*------------------------------------------------
Dim reccount As Double
'On Error Resume Next
Const adOpenStatic = 3
Const adLockOptimistic = 3
Const adCmdText = &H1
Set objConnection = CreateObject("ADODB.Connection")
Set objConn = CreateObject("ADODB.Connection")
Set objRecordset = CreateObject("ADODB.Recordset")

strPathtoTextFile = "C:\"

objConn.Open ("Provider=SQLOLEDB.1;Persist Security Info=False;User
ID=sa;Initial Catalog=stocks;Data Source=webserver1")

objConnection.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & strPathtoTextFile & ";" & _
"Extended Properties=""text;HDR=YES;FMT=FixedLength"""

objRecordset.Open "SELECT * FROM accounts.csv", _
objConnection, adOpenStatic, adLockOptimistic, adCmdText

Do Until objRecordset.EOF
strCSV = "update accounts set closed = 0 where accountid=" &
objRecordset.Fields.Item("AccountID")
objConn.Execute strCSV
objRecordset.MoveNext
Loop
objRecordset.Close
objRecordset.Open "select count(*) from accounts where closed=0",
objConn
MsgBox objRecordset(0)

*-------------------------------
"Allan Mitchell" <allan (AT) no-spam (DOT) sqldts.com> wrote in message
news:OJXDQwvSEHA.2480 (AT) TK2MSFTNGP10 (DOT) phx.gbl...
No real need here for DTS other then using it is a workflow engine.

Look up BULK INSERT in BOL.

Stage the data into a working entity and then use TSQL Statements to
do
your
UPDATEs

--
--

Allan Mitchell MCSE,MCDBA, (Microsoft SQL Server MVP)
www.SQLDTS.com - The site for all your DTS needs.
I support PASS - the definitive, global community
for SQL Server professionals - http://www.sqlpass.org


"Ashish Kanoongo" <ashishk (AT) armour (DOT) com> wrote in message
news:ewhpWmvSEHA.2944 (AT) tk2msftngp13 (DOT) phx.gbl...
I would like to create DTS for Importing from CSV using store
procedure,
in
which I would like to update fields conditionally.

Anyone can help in this matter or let me know url/tutorial on this.

Thanks in advance


---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.699 / Virus Database: 456 - Release Date: 06/04/2004




---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.700 / Virus Database: 457 - Release Date: 06/06/2004





---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.700 / Virus Database: 457 - Release Date: 06/06/2004




Reply With Quote
  #7  
Old   
John Bell
 
Posts: n/a

Default Re: Importing CSV file using store procedure - 06-08-2004 , 08:04 AM



Hi

The code would fit into your existing script.

John

"Ashish Kanoongo" <ashishk (AT) armour (DOT) com> wrote

Quote:
Thanks john. But I wouldlike to use this in DTS and I am new to DTS, so I
am
looking for a guidance for all sql Gurus.
"John Bell" <jbellnewsposts (AT) hotmail (DOT) com> wrote in message
news:ebc5m4UTEHA.2416 (AT) TK2MSFTNGP09 (DOT) phx.gbl...
Hi

This is untested but you may want to try opening the datasource within
the
update statement therefore there would be no need to step through the
record
set.

strCSV = "update a set closed = 0
from accounts a JOIN
OpenDataSource( 'Microsoft.Jet.OLEDB.4.0',
'Data Source=""" & strPathtoTextFile & """;" &
_
"Extended
Properties=""text;HDR=YES;FMT=FixedLength""')...ac counts.csv c
ON a.accountid= C.accountid"

objConn.Execute strCSV

John

"Ashish Kanoongo" <ashishk (AT) armour (DOT) com> wrote in message
news:OMvXzIRTEHA.2324 (AT) TK2MSFTNGP10 (DOT) phx.gbl...
I have following logic , how do use this logic in DTS. Here is my
logic

*------------------------------------------------
Dim reccount As Double
'On Error Resume Next
Const adOpenStatic = 3
Const adLockOptimistic = 3
Const adCmdText = &H1
Set objConnection = CreateObject("ADODB.Connection")
Set objConn = CreateObject("ADODB.Connection")
Set objRecordset = CreateObject("ADODB.Recordset")

strPathtoTextFile = "C:\"

objConn.Open ("Provider=SQLOLEDB.1;Persist Security Info=False;User
ID=sa;Initial Catalog=stocks;Data Source=webserver1")

objConnection.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & strPathtoTextFile & ";" & _
"Extended Properties=""text;HDR=YES;FMT=FixedLength"""

objRecordset.Open "SELECT * FROM accounts.csv", _
objConnection, adOpenStatic, adLockOptimistic, adCmdText

Do Until objRecordset.EOF
strCSV = "update accounts set closed = 0 where accountid=" &
objRecordset.Fields.Item("AccountID")
objConn.Execute strCSV
objRecordset.MoveNext
Loop
objRecordset.Close
objRecordset.Open "select count(*) from accounts where closed=0",
objConn
MsgBox objRecordset(0)

*-------------------------------
"Allan Mitchell" <allan (AT) no-spam (DOT) sqldts.com> wrote in message
news:OJXDQwvSEHA.2480 (AT) TK2MSFTNGP10 (DOT) phx.gbl...
No real need here for DTS other then using it is a workflow engine.

Look up BULK INSERT in BOL.

Stage the data into a working entity and then use TSQL Statements to
do
your
UPDATEs

--
--

Allan Mitchell MCSE,MCDBA, (Microsoft SQL Server MVP)
www.SQLDTS.com - The site for all your DTS needs.
I support PASS - the definitive, global community
for SQL Server professionals - http://www.sqlpass.org


"Ashish Kanoongo" <ashishk (AT) armour (DOT) com> wrote in message
news:ewhpWmvSEHA.2944 (AT) tk2msftngp13 (DOT) phx.gbl...
I would like to create DTS for Importing from CSV using store
procedure,
in
which I would like to update fields conditionally.

Anyone can help in this matter or let me know url/tutorial on this.

Thanks in advance


---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.699 / Virus Database: 456 - Release Date: 06/04/2004




---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.700 / Virus Database: 457 - Release Date: 06/06/2004






---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.700 / Virus Database: 457 - Release Date: 06/06/2004





Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.