Click here to Skip to main content
15,885,278 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi ,

i am trying to execute below Query but its give me the error---The conversion of a varchar data type to a datetime data type resulted in an out-of-range value.
SQL
INSERT into tblXy([Date],TransDate)
VALUES(REPLACE(CONVERT(VARCHAR(10), T.TransactionDate, 103), '/', '') ,REPLACE(CONVERT(VARCHAR(10),T.TransactionDate1, 103), '/', '')

plese help me...

thanks
Posted
Updated 17-Jul-12 0:37am
v2
Comments
Arul R Ece 17-Jul-12 6:35am    
Hi..

The value of TransactionDate is from same table r another table
vaquas 17-Jul-12 6:40am    
yes it is in other table
Arul R Ece 17-Jul-12 6:53am    
Which column is common for both table..

1 solution

Why? Why not convert it to a DateTime value and store that? All your code is doing is removing the parts that the DateTime conversion stuff could use to tell what part of the string you are feeding it is the day, the month and the year. If you are going to convert from a fixed format string to any other string based format, then convert to ISO (which SQL understands): "yyyy-MM-dd"
 
Share this answer
 
Comments
vaquas 17-Jul-12 6:39am    
because this format i need
OriginalGriff 17-Jul-12 6:49am    
Why? The error message is complaining that the format you generate is invalid to fit in a DateTime column - so hand it a DateTime or a string that will convert. Not a string you assemble that won't convert.
A DateTime column doesn't have a format when stored in a DB - just a value. The idea is that to convert to a DateTime as early and possible, and convert back to a string as late as possible. That way, it is easier to deal with international formats for example.
AmitGajjar 17-Jul-12 7:01am    
Perfect answer.... 5+

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900