Date parameter using with stored procedures in SQL Server - sql-server

I'm trying to retrieve data in iReport using stored procedure(SP) in SQL Server 2008.
My stored procedure uses two parameters Date_From & Date_To. I would like to run the report in specified (by these parameters) period but in any case I have info like "No data in report". In table the date is stored in format "yyyy-MM-dd 00:00:00.000". both of the parameters are set as "java.util.Date". In the Report query I have:
Query language = plsql
In query window: Name_of_procedure $P{Date_From}, $P{Date_To}
I found somewhere info that is possible to change the Date format and I have change it to:
Date format "yyyy-MM-dd", but after this change, instead of generate the report iReport is coming back to the Designer window, without any error or info.
May I ask for help, how to correct set the parameter that would provide the Date in format "yyyy-MM-dd"?
iReport version: 5.1.0

To see the error you can go to Window--> Report Output option there you can find the error.
To call the procedure syntax should be
CALL Name_of_procedure ( $P{Date_From}, $P{Date_To})
and to set the default value for parameters you can use this syntax.
new Date(114,7,06) --> to set default date as 06 Aug 2014.

Related

Calling a SQL Server Store Procedure from Excel PowerQuery with datetime parameters is not working for me

I am new to M.
When trying to call a SQL Server Store Procedure in M, I want to pass parameters to the exec command where SQL is looking for smalldatetime types. I have defined my parameters in PowerQuery as Date/Time, however, when they are added to the exec command I get various errors depending on how I include them.
PowerQuery Parameters
PowerQuery Code
Error Returned
If I change my query to convert the parameters from datetime to text using DateTime.ToText(startDate) I then get the error noting that my stored procedure needs a smalldatetime parameter type as follows, which is of course obvious:
DataSource.Error: Microsoft SQL: Error converting data type varchar to smalldatetime.
I also want to be able to submit the parameter in 'yyyy/mm/dd hh:mm' format, although if SQL will understand the month and day properly as my users will be in different regions of the world, then I will be happy. If I need to modify my stored procedure to work better with this, I can do that also.
Any help appreciated with thanks.

Day/Month/Year date changed to Month/Day/Year in SQL

I have an old Classic ASP application that was worked perfectly, recently it was moved to window server 2012 server with IIS 8.5, the problem is that I have a form to add record with Day/Month/Year format, when the date entered as 23/06/2015 in SQL will be added correctly as 23/06/2015 but when date entered as 01/06/2015 : 1st june 2015 in SQL will be added as 06/01/2015 Month/Day/Year which will be incorrect
I checked the location and date format for the server and it was dd/mm/yyyy, and the database didn't changed since the old server SQL 2008.
I searched the net and found the i need to change the IIS culture under GLOBALIZATION, but I don't know what to choose even if I chose my country still I am facing the same issue.
If you don't want to get into changing globalization and localization settings, the simple answer is to use the universal date input YYYYMMDD when inserting dates as strings.
Update
To expland on your comment: when changing the format of the date string in an insert/update query it does not change the format within the sql table itself.
e.g.
UPDATE [table]
SET [column] = '20150716 10:22'
WHERE Id = 7489
When viewed displays the same as the other records in the table:
Try this:-
https://www.webwiz.co.uk/kb/asp-tutorials/date-time-settings.htm
Add an entry into global.asa as below...
'When a session starts on the server the following code will be run
Sub Session_OnStart
'Set the server locale
Session.LCID = 2057
End Sub
Somethimes when nothing fix this problem (or a global solution could damage old scripts), A workaround that you could use is the convert function, to change the format in your stored procedure.
For Example:
select getdate() --prints 2018-10-05 12:24:43.597
select Convert(char(10),getdate(),103) --To force the date to be dd/mm/yyyy
And not leting the asp page to format the date, just print raw.

Query works in Query Designer but not in MS SQL Server Report Builder

While using the Microsoft SQL Server Report Builder, I am able to execute a query in the Query Designer and retreive the result. The query has a where clause on dates.
select * from table where DB_timestamp > to_date(:StartDate, 'mm/dd/yyyy') and DB_timestamp < to_date(:EndDate, 'mm/dd/yyyy')
On execution, I get a pop up where I enter the two variables (StartDate & EndDate) in the given formats. Now when I try to run the same for generating a report, I have to select the two variables using a calender picker. Altough the dates show up in the desired format, I always get the below error:
An error occured during local report processing.
Query execution failed for dataset 'XYZ'.
ORA-01843: not a valid month
What can cause the query to run successfully in one place but throw an error when the variables are selected by the calender picker?
There mught be some kind of culture clash going on. If SSRS is sending dd/mm/yyyy and your db is expecting mm/dd/yyyy things will not work as expected or even crash on certain dates.
I would remove the to_date function from the where clause, e.g.
where DB_timestamp > :StartDate and ...

Running SQL Transport Schema Generation Wizard with datetime parameter in biztalk

I am trying to run the SQL Transport Schema Generation Wizard against a SQL 2012 server. The stored procedure has a datetime parameter. If i simply put in a date like 12/26/2013 05:00:00 Am, then the "Generate" button doesn't show an argument. If i try putting the date/time in a single quote or using a string like 2013-12-26T05:00:00.000, the parameter is generated, but i get the following error when i try to execute. "Failed to execute SQL Statement. Please ensure that the supplied syntax is correct. "
I got to this point by creating a SQL Query that output it's response using FOR XML AUTO, ELEMENTS in it. I then open my BizTalk solution in VS 2012, Go to "Add Items -> Add Generated Items". Select Add Adapter Metadata. From there, it asks the location of the message box. I use my local server. It then asks for the connection string for the SQL Server with the stored procedure. I enter that (it's the same as the server with the message box). I specify the namespace and the root element name for the document. This is set as a receive port. I next select stored procedure and move to the next screen. I then select the stored proc from a drop down list. Below, in a grid, i am shown the parameters for the stored proc. Here is where i am having trouble. I cannot seem to get it to accept the datetime argument no matter what i put in here.
Is there something i am doing wrong?
It is better to do the following steps and to use the new WCF-SQL rather than the old deprecated SQL adapter.
Add Items
Add Generated Items
Consume Adapter Service
Select sqlBinding and Configure the URI
Click Connect
Select Client (Outbound operations)
Select Strongly-Type Procedures
Select the Stored Procedure from Available categories and operations
Click Add
Give it a Filename Prefix
Click OK
This will generated the schemas plus binding files to create the port.
You also don't need to have the FOR XML AUTO, ELEMENTS in your stored procedure any more.

unable to insert date into SQL using stored procedure from VB.NET form

I try to inset date into SQL server from textfield. I already tried to convert it but I always keep receiving same error:
Stored procedure 'XYZ' expects parameter ... which was not supplied.
Before I pass value of date to SQL Server I convert it into date:
upis.parameters.AddWithValue("#datum_start", DateValue(Datum_start.text))
I captured SQL Event with Profiler and I see that form passes value:
exec sp_executesql N'_osoba_zivotopis_test',N'#guid_kandidata nvarchar(36),#datum_start nvarchar(10),#datum_kraj nvarchar(10),#vodece int,#trenutno int',#guid_kandidata=N'24C40512-7292-403D-8C08-EEEA2C81EC7D',#datum_start=N'15.02.2012',#datum_kraj=N'01.10.2012',#vodece=0,#trenutno=0
Any ideas on this?
Thank you Sankaras, but problem was on the other side.
After writting 305 lines of code I missed to add code in stored procedure definition in my VB.NET code behind file
upis.CommandType = CommandType.StoredProcedure
When I defined CommandType everything works fine.
.NET knows to pass date value to SQL date data. Even I collect it in my form in local code environment .NET knows how to pass it and SQL knows how to handle it without convert(date,<varchar/nvarchar>,110)
I saw it after 10 minutes but I had to wait for 8 hours for post the answer...
Thank you guys.

Resources