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

Adding a DateTime field + a Character field In a Query

Status
Not open for further replies.

LeonelSanchezJr

Programmer
Jan 26, 2001
522
US
I have the following query, but I am getting an error stating, "The conversion of a char data type to a datetime data type resulted in an out-of-range datetime value."

The Time field is character and the Date field is DateTime.


Insert Into #Tmp3
Select A.Num,
A.Stat
From Stat A
Inner Join (Select Stat.cNum, Max(str(Stat.dDate)+Stat.cTime) As MaxDateTime
From Stat Group By Stat.cNum) As B
On A.cNum = B.cNum
And str(A.dDate)+A.cTime = B.MaxDateTime


 
Rather than the STR function, use CONVERT.

STR(Stat.dDate) --> CONVERT(char(10),Stat.dDate,101)

Style 101 gives mm/dd/yyyy format. You can choose whichever style you want as long as you use it consistently throughout the query. Terry

Neither success nor failure is ever final. -Roger Babson
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top