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
 Development Tools
 Reporting Services Development
 Conversion error
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

aarthirsk
Starting Member

India
5 Posts

Posted - 04/11/2014 :  06:23:58  Show Profile  Reply with Quote
Hi,

I'm getting conversion failed error while converting nvarchar to date/time.

I tried everything that has been given in forums.

SELECT LOCATION,SUM(SHIPQTY) LATE_QTY ,PO_DATE FROM mytable
AND SUBSTRING(CAST(PO_DATE AS DATE),1,2) + '/' + SUBSTRING(CAST(PO_DATE AS DATE),4,2)+'/'+
SUBSTRING(CAST(PO_DATE AS DATE) ,7,4) BETWEEN @Fromdate AND @Todate

I used convert,cast and cast as varchar and then to date.

But nothing works.

because of this problem the data is not properly filtered in report.if I filter for jan 2013 it gives me jan 2012 data
since I don't have data for jan 2013.But actually it should not return any value for jan 2013.

the date column in my table is in nvarchar format.

Pls advise.I spent almost a week for this.



the data looks like mm/dd/yyyy format but the data type is n varchar

gbritton
Flowing Fount of Yak Knowledge

1130 Posts

Posted - 04/11/2014 :  08:53:49  Show Profile  Reply with Quote
Are you missing a where clause in your query?

Also, is PO_DATE NVARCHAR? IF so, I have no problem with code like this:


declare @strdate as nvarchar(20) = '04/11/2014'

select cast(@strdate as date)


Finally, SUBSTRING will fail in your query since it wants to work with strings (hence the name)
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.05 seconds. Powered By: Snitz Forums 2000