Home All Groups Group Topic Archive Search About

Dates from multiple fields

Author
21 Oct 2005 3:35 PM
Blasting Cap
I have fields that are listed as nvarchar in a table.  Field1 contains
the month, Field2 contains the day, Field3 contains the year.

I need to pick stuff off this table with a "date" >= 12/10/2004.

How do you construct the "date" from the 3 fields above?

I've tried cast & converts on it, but have not hit the correct combination.

Any help appreciated.

BC

Author
21 Oct 2005 3:48 PM
SQL
concatenate and add '/'  between the fields and convert the whole thing to a
datetime

http://sqlservercode.blogspot.com/

Show quote
"Blasting Cap" wrote:

> I have fields that are listed as nvarchar in a table.  Field1 contains
> the month, Field2 contains the day, Field3 contains the year.
>
> I need to pick stuff off this table with a "date" >= 12/10/2004.
>
> How do you construct the "date" from the 3 fields above?
>
> I've tried cast & converts on it, but have not hit the correct combination.
>
> Any help appreciated.
>
> BC
>
>
Author
21 Oct 2005 3:48 PM
Jerry Spivey
Blasting,

Try:

SELECT <COLUMNS>
FROM  <TABLE>
WHERE CAST(CAST(FIELD3+FIELD2+FIELD1 AS CHAR(8)) AS DATETIME) <
ETDATE()  -- OR OTHER DATE

HTH

Jerry
Show quote
"Blasting Cap" <goo***@christian.net> wrote in message
news:uWQkDUl1FHA.1028@TK2MSFTNGP12.phx.gbl...
>I have fields that are listed as nvarchar in a table.  Field1 contains the
>month, Field2 contains the day, Field3 contains the year.
>
> I need to pick stuff off this table with a "date" >= 12/10/2004.
>
> How do you construct the "date" from the 3 fields above?
>
> I've tried cast & converts on it, but have not hit the correct
> combination.
>
> Any help appreciated.
>
> BC
>

AddThis Social Bookmark Button