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!

SQL statement help...

Status
Not open for further replies.

celauritz

Technical User
Dec 2, 2005
41
US
This is likely pretty simple, but I am a SQL newbie. I've been working around it for quite some time, but if I want things to be automatic, I need to figure little things like this out...

If I type this:

SELECT
CAST((CENTURY*1000000+YEAR*10000+MONTH*100+DAY)
AS VARCHAR(8))
AS DATE, ACCOUNT
FROM MASTER
WHERE CENTURY = 20 AND YEAR = 8 AND MONTH = 4 AND DAY = 1

I get a list looking like this:

DATE ACCOUNT
20080401 1000001
20080401 1000002
20080401 1000003

Is there any way to convert my new "DATE" into a date format? The columns are all numeric. I really don't need to change it to a varchar, and I don't really remember why I did so right now, so disregard it if you need to...

Thanks in advance...
 
You can use CAST('20080401' AS DATETIME) ;
--

woogoo
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top