dbTalk Databases Forums  

Datetime with vbscript?

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


Discuss Datetime with vbscript? in the microsoft.public.sqlserver.dts forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
tabladude@gmail.com
 
Posts: n/a

Default Datetime with vbscript? - 04-27-2005 , 12:16 PM






Hi:

There is a datetime field in a SQL Server database. Using ADO, I
extract the maximum date as follows:

strSQL = "SELECT MAX([Timestamp]) AS MaxDate FROM " & TableName

which I then execute. I then set a variable to this value:

varMaxDate = objRS.Fields("MaxDate")

and then I use this to set a SQL Statement:

sSQLStatement = "SELECT * FROM " & TableName & " WHERE Timestamp >= '"
& _
varMaxDate & "'"

The problem is, the resulting SQL Statement is a date, not a datetime.
What is the best way to create a SQL Statement that uses a real
datetime. This SQL Statement is to be used in a SQL Server DTS package
as a query against a Sybase database via ODBC (I'm using VB Script in
an ActiveX Script Task). So my goal is to look in the target table (SQL
Server) for the maximum datetime, and then get any records in the
source (Sybase) with a datetime greater than what is in the SQL Server
database.

Thanks,
Kayda


Reply With Quote
  #2  
Old   
Ato Bisda
 
Posts: n/a

Default Re: Datetime with vbscript? - 04-27-2005 , 03:27 PM






Have you tried using the FormatDateTime function?

==> varMaxDate = FormatDateTime(objRS.Fields("MaxDate"))


<tabladude (AT) gmail (DOT) com> wrote

Quote:
Hi:

There is a datetime field in a SQL Server database. Using ADO, I
extract the maximum date as follows:

strSQL = "SELECT MAX([Timestamp]) AS MaxDate FROM " & TableName

which I then execute. I then set a variable to this value:

varMaxDate = objRS.Fields("MaxDate")

and then I use this to set a SQL Statement:

sSQLStatement = "SELECT * FROM " & TableName & " WHERE Timestamp >= '"
& _
varMaxDate & "'"

The problem is, the resulting SQL Statement is a date, not a datetime.
What is the best way to create a SQL Statement that uses a real
datetime. This SQL Statement is to be used in a SQL Server DTS package
as a query against a Sybase database via ODBC (I'm using VB Script in
an ActiveX Script Task). So my goal is to look in the target table (SQL
Server) for the maximum datetime, and then get any records in the
source (Sybase) with a datetime greater than what is in the SQL Server
database.

Thanks,
Kayda




Reply With Quote
  #3  
Old   
kayda
 
Posts: n/a

Default Re: Datetime with vbscript? - 04-27-2005 , 05:53 PM



I tried doing that but I get a type mismatch error when I run the
package. How is that possible? It is a scripting language so I didn't
declare a datatype when I declared the variable. I tried also supplying
the zero argument as per the description at:

http://msdn.microsoft.com/library/de...atdatetime.asp

Any ideas why that is happening?

Thanks,
Kayda


Reply With Quote
  #4  
Old   
Ato Bisda
 
Posts: n/a

Default Re: Datetime with vbscript? - 04-27-2005 , 08:18 PM



It's probably a case of the NULLS. Using FormatDateTime on a null value will cause the data mismatch.

So your code should probably look like the following:

tempDate = objRS.Fields("MaxDate"))
If Not IsNull(tempDate) Then
varMaxDate = FormatDateTime(tempDate)
Else
varMaxDate = #1/1/1970#
End If

The #1/1/1970# is there to ensure varMaxDate always contains a legal date (for further processing later on).

"kayda" <tabladude (AT) gmail (DOT) com> wrote

Quote:
I tried doing that but I get a type mismatch error when I run the
package. How is that possible? It is a scripting language so I didn't
declare a datatype when I declared the variable. I tried also supplying
the zero argument as per the description at:

http://msdn.microsoft.com/library/de...atdatetime.asp

Any ideas why that is happening?

Thanks,
Kayda




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.