SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 conversion failed datetime from charcter string
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

sateesh.sqldba
Starting Member

India
25 Posts

Posted - 06/21/2010 :  01:57:02  Show Profile  Reply with Quote
Hello every one,
i got problem conversion failed date time from character string when i was run query it is working fine but when i put it in stored procedure it is sending this error

Set @EndDateString = Cast((@MonthNumber) as varchar) + ''/'' + Cast(@DayBackOneWeekforReport as varchar) + ''/'' + Cast((Year(@TodaysDate)-1) as varchar) + '' 23:59:59.000''

--Print @EndDateString


Set @EndDate = cast(@EndDateString as datetime)


Error:conversion failed datetime from charcterstring
at line 75




Thank you In Advance

sateesh

Edited by - sateesh.sqldba on 06/21/2010 07:51:23

senthil_nagore
Flowing Fount of Yak Knowledge

India
1007 Posts

Posted - 06/21/2010 :  02:01:32  Show Profile  Visit senthil_nagore's Homepage  Send senthil_nagore a Yahoo! Message  Reply with Quote
post your error!

Senthil.C
------------------------------------------------------
[Microsoft][ODBC SQL Server Driver]Operation canceled

http://senthilnagore.blogspot.com/
Go to Top of Page

senthil_nagore
Flowing Fount of Yak Knowledge

India
1007 Posts

Posted - 06/21/2010 :  02:04:06  Show Profile  Visit senthil_nagore's Homepage  Send senthil_nagore a Yahoo! Message  Reply with Quote
put a length on varchar datatype

http://beyondrelational.com/blogs/madhivanan/archive/2007/12/04/column-length-and-data-length.aspx


Senthil.C
------------------------------------------------------
[Microsoft][ODBC SQL Server Driver]Operation canceled

http://senthilnagore.blogspot.com/
Go to Top of Page

madhivanan
Premature Yak Congratulator

India
22772 Posts

Posted - 06/21/2010 :  03:01:44  Show Profile  Send madhivanan a Yahoo! Message  Reply with Quote
It should be

Set @EndDateString = Cast((@MonthNumber) as varchar) + ''/'' + Cast(@CurrentDayforReport as varchar) + ''/'' + Cast(Year(@TodaysDate) as varchar) + '' 23:59:59.000''


But I think you can effeciently use
Set @EndDateString = dateadd(month,@MonthNumber-1,dateadd(year,@TodaysDate-1900,@CurrentDayforReport)

Set @EndDate = cast(@EndDateString as datetime)

and use it in where clause as

where date_col<@EndDate

Also make sure to read these
http://beyondrelational.com/blogs/madhivanan/archive/2010/06/03/understanding-datetime-column-part-i.aspx
http://beyondrelational.com/blogs/madhivanan/archive/2010/06/03/understanding-datetime-column-part-ii.aspx

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

madhivanan
Premature Yak Congratulator

India
22772 Posts

Posted - 06/21/2010 :  08:08:57  Show Profile  Send madhivanan a Yahoo! Message  Reply with Quote
quote:
Originally posted by sateesh.sqldba

Hello every one,
i got problem conversion failed date time from character string when i was run query it is working fine but when i put it in stored procedure it is sending this error

Set @EndDateString = Cast((@MonthNumber) as varchar) + ''/'' + Cast(@DayBackOneWeekforReport as varchar) + ''/'' + Cast((Year(@TodaysDate)-1) as varchar) + '' 23:59:59.000''

--Print @EndDateString


Set @EndDate = cast(@EndDateString as datetime)


Error:conversion failed datetime from charcterstring
at line 75




Thank you In Advance

sateesh


What did you change?
Can you highlight it?

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.08 seconds. Powered By: Snitz Forums 2000