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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Numeric to DateTime Syntax

Status
Not open for further replies.

ddeegan

Programmer
Jun 17, 2002
193
US
Hello

I have fields (data type=decimal) to import into another field (data type=datetime)

The format of the numeric field is YYYYMMDD (20060801)

But, some of the numeric fields are equal to 0 or null.

What is the proper syntax for an insert statement?

Thanks in advance
Dave
 
Code:
Declare @Temp Decimal(10,0)

Set @Temp = 0

Select Convert(DateTime, Convert(VarChar(10), Nullif(@Temp, 0)))

If the value is NULL or 0, NULL will be returned. If the value is anything else, the conversion will take place.

-George

Strong and bitter words indicate a weak cause. - Fortune cookie wisdom
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top