I have a stored procedure that has structure like this:
ALTER PROCEDURE dbo.GetUserFullName
(#NoteStoreType INT = NULL)
AS
SELECT DISTINCT dbo.tblUsers.LastName + ', ' + dbo.tblUsers.FirstName as UnderwriterName
FROM tblUsers
WHERE tblUsers.Type = COALESCE(#NoteStoreType, tblNoteStore.Type )
In my SSRS report I want to say if #NoteStoreType= NULL then select ALL NoteStoreTypes, if not then use #NoteStoreType that user will select.
If I allow multiple values then it gives me an error converting datatype int to string.
Can I do that in SSRS without changing anything in my stored procedure?
The multiple parameters that are selected will get passed to stored proc as a string. You will need to change stored proc to split this string. Also if you want to pass null you will need to check the allow null value.
Related
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 am trying to re-create a stored procedure for testing a specific application scenario, but I don't have enough access to view the original stored procedure. I can see the application runs a query like:
exec dbo.SP_GET_WORKSTATIONS #WORKSTATION_FID=N'%',#VALID_IND=N'%',#WORKSTATION_DOMAIN=N'%',#WORKSTATION_PID=N'%'
Based on the input data type results of the original stored procedure, and results it returned I built a stored procedure like this:
CREATE PROCEDURE [dbo].[SP_GET_WORKSTATIONS]
#WORKSTATION_FID varchar(32),
#VALID_IND char(1),
#WORKSTATION_DOMAIN char(20),
#WORKSTATION_PID varchar(10)
AS
SELECT
WORKSTATION_FID as Code,
VALID_IND as ValidInd,
WORKSTATION_DOMAIN As Name,
WORKSTATION_PID as PId
FROM
[dbo].[L_WORKSTATIONS]
WHERE
WORKSTATION_FID LIKE #WORKSTATION_FID AND
VALID_IND LIKE #VALID_IND AND
WORKSTATION_DOMAIN LIKE #WORKSTATION_DOMAIN AND
WORKSTATION_PID LIKE #WORKSTATION_PID;
GO
However this doesn't return any data, however if I run
SELECT
WORKSTATION_FID as Code,
VALID_IND as ValidInd,
WORKSTATION_DOMAIN As Name,
WORKSTATION_PID as PId
FROM
[dbo].[L_WORKSTATIONS]
WHERE
WORKSTATION_FID LIKE '%' AND
VALID_IND LIKE '%' AND
WORKSTATION_DOMAIN LIKE '%' AND
WORKSTATION_PID LIKE '%'
I get results. If I change the LIKE in stored procedure to = and specify exact parameters, the stored procedure works.
Your #WORKSTATION_DOMAIN parameter should be varchar not char.
Trailing space is significant in the like pattern and % followed by 19 spaces (padded out to 20 characters) will try and match content ending with 19 spaces.
Trailing space is ignored in equality comparisons.
Be aware that there may be the need to pass in different parameters that like % and depending on the datatypes your proc might not work. More than likely the original was created using dynamic SQL so it could handle a list of values and different datatypes.
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
I have a simple stored procedure, which executes in base of one input parameter. But I have to execute it about 100 times because of different parameters (parameter is int)Is there any other way except of inputing parameter values one by one? I mean something like #parameter in (value 1, value 2, .....value n).Thanks a lot.
This is the procedure:
ALTER PROCEDURE procname
#parameter AS BIGINT
AS
DELETE FROM tbl1 WHERE id = #parameter
DELETE FROM tbl2 WHERE tbl2_field=#parameter
DELETE FROM tbl3 WHERE tbl3_field=#parameter
DELETE FROM tbl4 WHERE tbl4_field=#parameter
1) make the parameter optional
2) when parameter is provided, use it to filter the results
3) when parameter is null, return all results, grouped on the field represented by the parameter.
Such as :
Select EmpNum, EmpNameFull, DeptName, HireDate
From Employee
Where DeptName = paramDeptName
or paramDeptName IS NULL
Order
By DeptName
, EmpNameFull
You could pass an array to the stored procedure. This is already answered with different database versions and multiple solutions on Stack Overflow here:
How to pass an array into a SQL Server stored procedure
and here
Passing an array of parameters to a stored procedure
Another solution could be to send the parameter comma separated and split it in T-SQL and loop through the values, How to split a comma separated string and loop its values in SQL Server (string parameter would be needed).
I have a SSRS Report that passes a value to my stored procedure. In the stored procedure, I have the following:
select * from ItemTable where Items in #ItemValues
Previously, this will work as #ItemValues can be multiple values between 1 to 5. However, now a null check has to be done so how can I do this with a null statement ?
You can use this statement in your procedure .
select * from ItemTable where #ItemValues IS NULL OR Items in #ItemValues