user3827129 user3827129 - 1 month ago 11
SQL Question

Year Number/Month Short Text Columns to Dates MS Access SQL

I've been trying to alter two columns (YR - Number Format & MTH - Short Text). I've been trying to just use the below code.

ALTER TABLE Table1
ALTER COLUMN YR DATE;


But it just ends up deleting the entries. I have a column of Years - Number Format & Months - Short Text that I want them to say the same thing, but in a Date format so I can reference them.

I have...

2006 - Number

JAN - Short Text


I need them to be...

2006 - YYYY

JAN - MMM


so I can reference them. Any suggestions would be appreciated.

Answer

Consider something like:

SELECT t.Years, t.Months, CDate([years] & "/" & [months] & "/1") AS ADate
FROM Table1 t
Comments