Datetime issues in SSRS
I am tearing my hair out! I am working with a vendor's database where the dates are saved in SQL 2008 as varchar dd/mm/yyyy hh:mm:ss. In SQL Management Studio I have written the query I want, using CONVERT(datetime, field, 103) to convert to
a datetime datatype so that when used in comparison I am getting returned exactly what I expected. However, when I paste the same SQL into the query for the dataset in SSRS, pointing to the same database in SQL, the date is being returned
as dd/mm/yyyy and being checked in this format and returning the wrong values when compared to the SQL date format yyyy-mm-dd because it is interpreting it as mm/dd/yyyy.
I had changed the language on my report to en-GB and thought maybe that was the problem, but leaving the report language to default is not changing the outcome.
I have tried saving the query as a stored procedure on the database, but this doesn't change the results when running it from SSRS. First returned record from Management studio gives me:
2011 45 2011-45 2012-02-05 00:00:00.000 Incident 2 1
Same query in SSRS gives me
2011 45 2011-45 05/02/2012 00:00:00.000 Incident 2 1
but because of date checks in the query I am not getting the consistent results returned. Why am I being so dim?! This has to be something really straightforward, but I can'twork out what!
Sue Neilson Sovereign Business Integration plc
August 24th, 2012 11:45am
Please, check the regional settings of your SSRS server (under Control Panel)Sebastian Sajaroff Senior DBA Pharmacies Jean Coutu
Free Windows Admin Tool Kit Click here and download it now
August 24th, 2012 1:53pm
Change the report language to =User!Language
It will use the regionnal setting for the formats.
August 24th, 2012 2:43pm
Thanks to both Alex and Sebastien - but neither of these make any difference.
The SQL server is set to English UK regional settings in Control Panel. And if I run the report with User!Language I am still missing the same data, and my own settings are English UK. From Management Studio on my laptop, connecting to
the SQL server, the query is perfect. From the Visual Studio project on my laptop, same SQL database, English UK report settings or not, data is missing.
But - the Properties of the SQL Server in Management Studio show that the language is English US - but then this would be true whether I was accessing it through Management Studio or Visual Studio? So I still don't understand why I am getting different results....Sue Neilson Sovereign Business Integration plc
Free Windows Admin Tool Kit Click here and download it now
August 29th, 2012 6:32am
I have made one further discovery on this - which I should have recognised before. Originally when running from both Management Studio and Visual Studio, I had the query coded as text. I have now put the same code into a stored procedure in
the database. Now if I exec the stored procedure in Management Studio with the same parameters, I get the same results (with data missing) as I have always been getting from Visual Studio. But exactly the same code in a query editor window, same
parameters, gives me the results I want and expect. I feel that this should point to exactly where my issue is - but at the moment I can't see it.Sue Neilson Sovereign Business Integration plc
September 4th, 2012 8:19am
I am still not sure why the query editor gave inconsistent results to the query in SSRS - but we have now resolved this. We examined the execution plans in SQL for both the stored procedure and the query editor and they were significantly different.
Have now discovered the principle of parameter sniffing! Adding two new date variables in the stored procedure and assigning the parameter values to them means that I now get consistent results. So sorry this was posted on the wrong forum!!
Sue Neilson Sovereign Business Integration plc
Free Windows Admin Tool Kit Click here and download it now
September 7th, 2012 11:50am