I have a dataset that is driven by a stored procedure requiring a parameter. The parameter is DATETIME but I am unable to present in that way in the report because DateTime's show as a calendar and I need a dropdown of values.
Alas, I have a dataset that drives the choices for the parameter called BaselineDate. The issue comes down to the way that SSRS formats the DateTime value for the parameter then passes as VARCHAR to the stored procedure. The VARCHAR value is in the wrong format.
SSRS
Expected Value
2016-04-07 13:01:19.173
Update
Per #Marco Bong's suggestions I have converted the dataset that is driving the Parameter options to the proper format. Unfortunately, SSRS I passing the parameter value as null.
Below is what is a debug table I created. I am simply inserting the value of the parameter into this table. As you can see SSRS is passing null to the stored procedure as NULL which in theory should be impossible as the parameter is set to not allow nulls. Any ideas?
select CONVERT(NVARCHAR,getdate(),21) as dtValue
//output will be ===> 2016-04-13 08:32:16.697
Update
If you want to use that selected value in another dataset (which execute your store prod), you may need to do this:
Then you can use this #param1 in your query.
Either where something = #param or set #baselineDate = #param
Related
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.
My SSRS report has one dataset (datasetMacys) that calls usp_GetStoreSales #Rundate, #StoreName.
Can the dataset have a default value? That way the report will only ask for one parameter (#Rundate) and the dataset has the string value "Macys" embedded?
In other words, the user will not have to select a value for the second parameter because it's already the default value of that dataset.
I would then add a 2nd dataset (datasetSears) where the default value for #StoreName is "Sears", which means it will only use the #Rundate that the user selected.
The stored procedure looks like this, even though it's not really needed for the question:
create procedure usp_GetStoreSales
(
#RunDate date,
#StoreName varchar(10)
)
as
select * from [Sales]
where RunDate = #RunDate and StoreName = #StoreName
I can easily fix this problem by creating two different stored procedures (ie. usp_GetMacysSales #RunDate and usp_GetSearsSales #RunDate), but that's exactly what I want to avoid.
You just need to create your two datasets and then, for each dataset, righ click the dataset name, choose properties, click the parameters tab and overwrite the parameter value for the StoreName parameter.
Yes - you can have a default value for the parameter of a dataset.
In the Parameters tab of the Dataset Properties, you can type in (hard code) a value in the Parameter Value expression box.
Of course the next question would be WHY? There may be better ways to do it.
If you are going to have both sets of data, why not make a query that combines the data into one so you only have one dataset?
I tried using
Where Location IN(#Location)
in my storedprocedure
In SSRS
i used =join(Parameters!Location.Value,",")
When i select all values the result is null
The value is in string format
Eg: 'XXXX,YY','yyy,mm'
You need to change your Sql stored procedure code so that it could recognize the comma separated values being passed from SSRS.
One way would be using table-value function that can split a comma-delimited string back out into a mini table - link
Once done the code in your stored procedure should be like this -
WHERE Location IN (SELECT Param FROM dbo.fn_MVParam(#Location,','))
I currently have a set of drop down parameters that pass dates to a query. There is a display value available to select for each Work Week.
Create Date Parameter:
Display in the drop down: 2016 01 (1/3/2016) P01-16 Q1-16
Value being passed to the SQL is WEEK_BEGIN_DATE: 1/3/2016
New Ship Date Parameter:
Display in the drop down: 2016 01 (12/27/2016) P12-15 Q4-15
Value being passed to the SQL is SHIP_WEEK_BEGIN_DATE: 12/27/2016
I would like to be able to make both of these optional.
I tried the following in the parameter value SQL to get the parameter to allow nulls but I got a data type error. I did start going down the cast as varchar() route but it was getting messy quick.
SELECT 'NULL' AS WEEK_BEGIN_DATE
UNION
SELECT d.WEEK_BEGIN_DATE FROM DATE d
Any suggestions are much appreciated. Let me know if I can provide any other helpful info.
this should work, you don't need the single quotes
SELECT NULL AS WEEK_BEGIN_DATE
UNION
SELECT d.WEEK_BEGIN_DATE FROM DATE d
to make parameters optional you could in where clause write something like
where (WEEK_BEGIN_DATE = #date or #date is null)
If your parameter of dates was a VARCHAR() you would need to do what Kostya stated. But since it's not, you can click "Allow null value" under Report Parameter Properties (rightclick on your parameter and select properties)
how can i pass a value from one dataset value as a variable/parameter into another dataset query to populate a table cell?
eg. Table displaying DataSet1 results. Last column comes from DataSet2 which has following query
SELECT * FROM tbl WHERE = $1
The WHERE value I want to come from a field value from DataSet1 resultset. How can I do this?
Thanks
You should be able to set up an internal parameter with your other dataset using "Default Values" "Get values from a query", then reference this parameter in your other dataset. Note your SQL Syntax needs correction in the WHERE clause. Note you may see an error if the dataset to be populated executes before the populating dataset.
If your second table is in a subreport, you can pass the field from your first query by simply referencing it as a parameter in the subreport:
=Fields!DataValue.Value