| Author |
Topic |
|
Xerxes
Aged Yak Warrior
666 Posts |
Posted - 2005-08-15 : 13:50:39
|
I have this code in my SQA:SELECT distinct NAME,CAST(BIRTHDATE as datetime) as DOB,BIRTHDATEINTO [Xerxes].[dbo].[new_tab]FROM [Xerxes].[dbo].[old_tab]GOBut, of course, I'm getting the time stuff as well as the date under 'DOB' [1775-11-10 00:00:00.000]. How do I shave the time from the date in the select statement?Semper fi, XERXES, USMC(Ret.)------------------------------------------------------The Marine Corps taught me everything but SQL! |
|
|
TG
Master Smack Fu Yak Hacker
6065 Posts |
Posted - 2005-08-15 : 13:58:12
|
| try executing the code while traveling many times the speed of light. That should shave a little time off...Are you saying you want a datetime result but at 12:00 am (00:00:00.000) or a varchar value with just the date?Be One with the OptimizerTG |
 |
|
|
Xerxes
Aged Yak Warrior
666 Posts |
Posted - 2005-08-15 : 14:01:46
|
What I want is just the date:instead of: 1775-11-10 00:00:00.000I want: 1775-11-10or, actually 10/11/1775......what kind of razor do I use?Semper fi, XERXES, USMC(Ret.)------------------------------------------------------The Marine Corps taught me everything but SQL! |
 |
|
|
TG
Master Smack Fu Yak Hacker
6065 Posts |
Posted - 2005-08-15 : 14:06:55
|
| Well then we're talkin' varchar:That's usually returned as datetime and formatted in the presentation layer but here's the sql version:select convert(varchar,BIRTHDATE,101).Be One with the OptimizerTG |
 |
|
|
Xerxes
Aged Yak Warrior
666 Posts |
Posted - 2005-08-15 : 14:15:09
|
Uh, TG, uh....that's a sticking point. That's why I'm asking the question. Because later on I'll want to do a comparison on the DOB....likeSELECT distinct NAME,CAST(BIRTHDATE as datetime) as DOB,[BIRTHDATE],TERMINTO [Xerxes].[dbo].[new_tab]FROM [Xerxes].[dbo].[old_tab]WHERE (RIGHT(TERM,4) = 0000 or RIGHT(TERM,4) > 2005) and (DOB > 09/30/2003)GOSo....that's why I used the CAST.....any other ideas?Semper fi, XERXES, USMC(Ret.)------------------------------------------------------The Marine Corps taught me everything but SQL! |
 |
|
|
TG
Master Smack Fu Yak Hacker
6065 Posts |
Posted - 2005-08-15 : 14:29:36
|
Sorry Xerxes I'm still not clear. What datatype is the source <date> now? Once you have datetime datatypes you can easily do comparisons on years or dates or whatever without needing to do conversions to varchar. Some examples:select dateadd(year, datediff(year,0,getdate()),0) --use to compare years ,datepart(year, getdate()) -- to compare and int to the year portion ,dateadd(day, datediff(day,0,getdate()),0) --use compare dates (without time) Be One with the OptimizerTG |
 |
|
|
X002548
Not Just a Number
15586 Posts |
|
|
Xerxes
Aged Yak Warrior
666 Posts |
Posted - 2005-08-15 : 15:02:04
|
Unfortunately, doing this .....SELECT distinct NAME,CONVERT(varchar(10),BIRTHDATE,120) as DOB, [BIRTHDATE],TERM INTO [Xerxes].[dbo].[new_tab]FROM [Xerxes].[dbo].[old_tab]GO....................doesn't make this work....SELECT distinct NAME, DOB, [BIRTHDATE],TERM INTO [Xerxes].[dbo].[new_tab]FROM [Xerxes].[dbo].[old_tab]WHERE (RIGHT(TERM,4) = 0000 or RIGHT(TERM,4) > 2005) and (DOB < '2003-09-30') GO.......as I'm still getting DOBs outside the range I indicated....Semper fi, XERXES, USMC(Ret.)------------------------------------------------------The Marine Corps taught me everything but SQL! |
 |
|
|
TG
Master Smack Fu Yak Hacker
6065 Posts |
Posted - 2005-08-15 : 15:15:09
|
try this:WHERE (RIGHT(TERM,4 = 0000 or RIGHT(TERM,4) > 2005) and DOB < '2003-09-30' EDIT:oh...is that the same thing?yeah it is...what is the datatype of DOB from old_tab? What values are violating your where clause?better post some DDL/DML...Be One with the OptimizerTG |
 |
|
|
Xerxes
Aged Yak Warrior
666 Posts |
Posted - 2005-08-15 : 15:21:55
|
quote: Originally posted by TG try this:WHERE (RIGHT(TERM,4 = 0000 or RIGHT(TERM,4) > 2005) and DOB < '2003-09-30' EDIT:oh...is that the same thing? HA,HA, real funnyyeah it is...what is the datatype of DOB from old_tab? What values are violating your where clause?better post some DDL/DML...Be One with the OptimizerTG
Semper fi, XERXES, USMC(Ret.)------------------------------------------------------The Marine Corps taught me everything but SQL! |
 |
|
|
|