Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Error: Cdate

Status
Not open for further replies.

mistektips

Programmer
Apr 4, 2006
20
0
0
US
Hi,

I am getting 'Type Mismatch: cdate error" when I am running this script...
Basically I am using DTS(Sql server) to transfer data...
And one of the columns is date...
Could someone suggest as to why I am getting an error?

Any help will be appreciated.
Thanks

The script is as follows:
Code:
'**********************************************************************
'  Visual Basic Transformation Script
'************************************************************************

'  Copy each source column to the destination column

Function Main()
	If DTSSource("A0015_ABOLISH_DATE") = "0" Then
		processdatef = "01/01/1901"
	Else
		processdate = CStr(DTSSource("A0015_ABOLISH_DATE"))
		processdatef = Mid(DTSSource("A0015_ABOLISH_DATE"), 5, 2) + "/" +  Mid(DTSSource("A0015_ABOLISH_DATE"), 7, 2) + "/" +  Mid(DTSSource("A0015_ABOLISH_DATE"),1,4)
	End If
	DTSDestination("Abolish_Date") = CDate(processdatef)
	Main = DTSTransformStat_OK
End Function
 
What comes out of DTSSource("A0015_ABOLISH_DATE")? Why not just print it out?

Why are you converting it to a string and then just using the value straight from the DB?
Code:
function main ()
   processdate = cstr(DTSSource("A0015_ABOLISH_DATE"))
   wscript.echo processdate
   if processdate = "0" then
      processdatef = "01/01/1901"
   else
      processdatef = mid(processdate, 5,2) & "/" & _
                    mid(processdate,7,2) & "/" & _
                    mid(processdate,1,4)
      wscript.echo processdatef
   end if
...
end function
 
When I try the above, I am getting an error in this line:
object required for wscript...
 
DTS script execution does not provide the WScript object.

[red]"... isn't sanity really just a one trick pony anyway?! I mean, all you get is one trick, rational thinking, but when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick[/red]
 
I tried validating using IsDate function:
If Not IsDate(DTSSource("A0015_ABOLISH_DATE")) Then
processdatef = "01/01/1901"

But I am not getting the right result...All the values are displayed as 01/01/1901

How else can i validate this date?
 
Try this instead.
[tt]
Function Main()
If len(DTSSource("A0015_ABOLISH_DATE"))<>8 or not isnumeric(DTSSource("A0015_ABOLISH_DATE")) Then
processdatef = "1901-1-1"
Else
processdatef = Mid(DTSSource("A0015_ABOLISH_DATE"),1,4) & "-" & Mid(DTSSource("A0015_ABOLISH_DATE"), 5, 2) & "-" & Mid(DTSSource("A0015_ABOLISH_DATE"), 7, 2)
End If
DTSDestination("Abolish_Date") = CDate(processdatef)
Main = DTSTransformStat_OK
End Function
[/tt]
My change of separator "/" to "-" is not essential.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top