Sunday, February 19, 2012

Imporint CSV file using store procedure

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
Ashish,
there are various ways of doing this. My preference is to import the data to a staging area in SQL Server then use Execute SQL tasks (TSQL) to clean/transform it, before importing it to the production system. Alternatively you can do row by row iteration and for each row decide what to do using VBScript. It sounds like this is the route you're interested in, and in that case the Transform data task with Lookup queries would be useful. For more info, have a look at http://www.sqldts.com/default.aspx?277.
HTH,
Paul Ibison
|||I made the logic in , but how do 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)
*--
"Ashish Kanoongo" <ashishk@.armour.com> wrote in message news:uvSKyXuSEHA.3988@.tk2msftngp13.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
|||Ashish,
have a look at the Transform Data Task with lookups integrated (lookups can
also do updates, despite their name)
http://www.sqldts.com/default.aspx?277,1
HTH,
Paul Ibison

No comments:

Post a Comment