Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Do I have to CAST a date?

Author  Topic 

Amber_Deslaurier
Starting Member

40 Posts

Posted - 2010-06-24 : 20:27:34
Hi,

I am linking Teradata to Excel dynamically and I want to know if I should CAST a date as date before I make the link... in my SQL code I will want to put a restriction so that it only extract the most latest date...

what should the code look like to retrieve the data based on the latest date? example: Max(date_a) ?

ty

Amber

slimt_slimt
Aged Yak Warrior

746 Posts

Posted - 2010-06-25 : 01:28:48
hi,

CAST is used only to convert data from one to another data type. so this won't help your query to retrieve the newest records.


to extract the most latest data using date something like:


select * from MyTable
where Date > convert(varchar(10), getdate(),120)


Code my differ on which datatype date is in your database, but this query should take only today's data.

otherwise, describing your case is a matter of either thorough ETL process to insert all the data missing on destination and present on source and updating data present both on source and destination, but with changes on source.
Go to Top of Page

AndrewMurphy
Master Smack Fu Yak Hacker

2916 Posts

Posted - 2010-06-25 : 03:10:23
Your convert is also unnecessary.

select * from mytable where mydate > (select max somecontroldate from somewhere)

There is no need to convert formats, unless the somecontroldate is not in "date" format.
Compare a date field to a date field.

Comparing a date to a character format version of a date brings in locaalisation issues - i.e. USA date formats, UK Date formats, Swedish date formats etc....
Go to Top of Page

Amber_Deslaurier
Starting Member

40 Posts

Posted - 2010-06-25 : 06:18:18
Thanks I will try it out
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2010-06-25 : 09:48:17
quote:
Originally posted by Amber_Deslaurier

Hi,

I am linking Teradata to Excel dynamically



"Run Away!!!" -- MPHG

Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

Add yourself!
http://www.frappr.com/sqlteam



Go to Top of Page

Michael Valentine Jones
Yak DBA Kernel (pronounced Colonel)

7020 Posts

Posted - 2010-06-25 : 10:36:57
quote:
Originally posted by slimt_slimt

hi,

CAST is used only to convert data from one to another data type. so this won't help your query to retrieve the newest records.


to extract the most latest data using date something like:


select * from MyTable
where Date > convert(varchar(10), getdate(),120)


Code my differ on which datatype date is in your database, but this query should take only today's data.

otherwise, describing your case is a matter of either thorough ETL process to insert all the data missing on destination and present on source and updating data present both on source and destination, but with changes on source.



Seems unlikely that this would be valid in Teradata SQL
where Date > convert(varchar(10), getdate(),120)



Amber_Deslaurier:
This forum is for questions about Microsoft SQL Server not Teradata, so you should post your questions on a forum where they answer Teradata questions.






CODO ERGO SUM
Go to Top of Page
   

- Advertisement -