I have a table (tblstudent) with four fields, Fname, Lname, City, Zip.
I want to run a DTS export nightly that export the records out to a file.
The kick is that I would like the text file to list the fields on their own
line like:
Fname
Lname
City
Zip
Instead of across like: Fname, Lname, City, Zip.
How can I accomplish this?
Thanks for your time!
TonyHopefully this will solve your issue. write the code in Axtivex script in DT
S.
========================================
=========
'***************************************
*********************
' Visual Basic ActiveX Script
'***************************************
*********************
Function Main()
Set Conn = CreateObject("ADODB.Connection")
Conn.Provider = "sqloledb"
Conn.Properties("Data Source").Value = "(local)"
Conn.Properties("Initial Catalog").Value = "Testing"
Conn.Properties("Integrated Security").Value = "SSPI"
Conn.CommandTimeout = 0
Conn.Open
'--get students record set
SqlQuery ="select * from tblStudent"
Set RsStudent = Conn.Execute(SQLQuery)
'--ourt vars
ourputString = ""
Path = "C:\test\"
'-- create output folder
Set objFSO = CreateObject("Scripting.FileSystemObject")
If Not objFSO.FolderExists(path) Then
objFSO.CreateFolder (path)
End If
'--Create Traget file
Set TargetFile = objFSO.CreateTextFile(Path &"Report.txt", True)
IF not RsStudent.eof Then
While not RsStudent.eof
ourputString=""
ourputString="Fisrt Name: " & RsStudent("FName") & vbcrlf & _
"Last Name:" & RsStudent("Lname") & vbcrlf & _
"City :" & RsStudent("City") & vbcrlf & _
"Zip :" & RsStudent("Zip") & vbcrlf & _
"----
--" & vbcrlf
TargetFile.WriteLine(ourputString)
RsStudent.moveNext
Wend
End If
Set TargetFile=Nothing
Set objFSO=Nothing
Set RsList =Nothing
Conn.close
set conn = nothing
Main = DTSTaskExecResult_Success
End Function
========================================
=========
"tony tuso" wrote:
> I have a table (tblstudent) with four fields, Fname, Lname, City, Zip.
> I want to run a DTS export nightly that export the records out to a file.
> The kick is that I would like the text file to list the fields on their ow
n
> line like:
> Fname
> Lname
> City
> Zip
> Instead of across like: Fname, Lname, City, Zip.
> How can I accomplish this?
> Thanks for your time!
> Tony
>
>
Showing posts with label fname. Show all posts
Showing posts with label fname. Show all posts
Tuesday, March 27, 2012
Wednesday, March 7, 2012
DTS - Write Exceptions to table?
Can DTS write exceptions to a database table? In the code
below, I copy fname, lname and (at the end) company from
the source to the destination. However, with title, if the
title is executive or president, the title is copied over;
if the title is ceo it is entered into the destination
table as ceo/chairman; if none of these conditions apply
(i.e. title is owner) I want the entire row written to a
new table.
If I use Main = DTSTransformStat_SkipRow, rows that meet
the title criteria are entered into the destination table,
and the rows that don't meet the criteria are not entered.
I can get DTS to output the exeption file to a text file,
however, with the large number of records that don't meet
the criteria, it would be better to have them in a new
table.
Thanks,
Jay
----------
Function Main()
DTSDestination("fname") = DTSSource("fname")
DTSDestination("lname") = DTSSource("lname")
'Check Titles
If lcase(DTSSource("title")) = "executive" then
DTSDestination("title") = DTSSource("title")
ElseIf lcase(DTSSource("title")) = "president" then
DTSDestination("title") = DTSSource("title")
ElseIf lcase(DTSSource("title")) = "ceo" then
DTSDestination("title") = "CEO/Chairman"
Else
Main = DTSTransformStat_ExceptionRow
'Main = DTSTransformStat_SkipRow
Exit Function
End if
DTSDestination("company") = DTSSource("company")
Main = DTSTransformStat_OK
End FunctionYou can break your task in 2 phases:
First Transformation Task:
Insert / Update all rows that meet the criteria
Second Transformation Task:
Insert rows that does not meet the criteria in a anther table
Remeber the you can have more than one transformatrion task between two connections|||Thanks - I will give that a try.
below, I copy fname, lname and (at the end) company from
the source to the destination. However, with title, if the
title is executive or president, the title is copied over;
if the title is ceo it is entered into the destination
table as ceo/chairman; if none of these conditions apply
(i.e. title is owner) I want the entire row written to a
new table.
If I use Main = DTSTransformStat_SkipRow, rows that meet
the title criteria are entered into the destination table,
and the rows that don't meet the criteria are not entered.
I can get DTS to output the exeption file to a text file,
however, with the large number of records that don't meet
the criteria, it would be better to have them in a new
table.
Thanks,
Jay
----------
Function Main()
DTSDestination("fname") = DTSSource("fname")
DTSDestination("lname") = DTSSource("lname")
'Check Titles
If lcase(DTSSource("title")) = "executive" then
DTSDestination("title") = DTSSource("title")
ElseIf lcase(DTSSource("title")) = "president" then
DTSDestination("title") = DTSSource("title")
ElseIf lcase(DTSSource("title")) = "ceo" then
DTSDestination("title") = "CEO/Chairman"
Else
Main = DTSTransformStat_ExceptionRow
'Main = DTSTransformStat_SkipRow
Exit Function
End if
DTSDestination("company") = DTSSource("company")
Main = DTSTransformStat_OK
End FunctionYou can break your task in 2 phases:
First Transformation Task:
Insert / Update all rows that meet the criteria
Second Transformation Task:
Insert rows that does not meet the criteria in a anther table
Remeber the you can have more than one transformatrion task between two connections|||Thanks - I will give that a try.
Subscribe to:
Posts (Atom)