able to select multiple dates (parameter) in ssrs - reporting-services

Is there a way where in I can select multiple dates and pass it as my parameters for a stored proc for a report in ssrs. selecting allow multiple values for a parameter gives a dropdown list. but can i get a calender control where I can select Multiple dates.

SQL Server Reporting Services, as of version 2008R2, does not have this functionality built in. I haven't looked at 2012, but I'd be surprised if it offered this.
(You can always build your own interface using a ReportViewer control, URL access or another access method to display reports.)

As Jamie stated, you can't really do this. The "best" work around I have come across in my experience is to pass your parameter value(s) as one text string, and use a split function to parse in your WHERE condition in the stored proc.
USE [YOUR DATABASE]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE FUNCTION [dbo].[split](
#delimited NVARCHAR(MAX),
#delimiter NVARCHAR(100)
) RETURNS #t TABLE (id INT IDENTITY(1,1), val NVARCHAR(MAX))
AS
BEGIN
DECLARE #xml XML
SET #xml = N'<t>' + REPLACE(#delimited,#delimiter,'</t><t>') + '</t>'
INSERT INTO #t(val)
SELECT r.value('.','varchar(MAX)') as item
FROM #xml.nodes('/t') as records(r)
RETURN
END
Your parameter would be something like this in your stored proc:
#Parameter VARCHAR(200)
Then your where condition in your stored proc will be something like this
where convert(varchar(10), cast([YOURDATE] as date), 101) IN (select val from dbo.split(#Paramater,','))
I hope this helps!

Related

SSRS-Report -How to get table name from parameters

I am trying to get table name from parameters, then i will use that to my query like
declare #cmd nvarchar(100)
declare #tableName nvarchar(100)
select #cmd = ' select * from ' + #tableName
execute (#cmd)
when i try to run with query designer dataset, it popup error message like
the declare sql construct or statement is not supported
What am I missing that needs to be there or what is causing this issue?
i hope somebody can give a hand how to solve it
thanks
It's just the query designer that cannot support this for obvious reasons. Just click "Edit as text" in the top left corner of the query designer and then you can do whatever you like.
Just remember that your dataset must always return the same column names in the same order with the same datatypes.

How to capture what parameters are passed to stored procedure inside ssis package runtime

I have a scenario where my client informed me that their sql server agent jobs fail sometimes. On investigation, we found that the sql agent job calls an ssis package, which internally calls an SP with parameters (?,?,?), and the error is being generated in TSQL inside SP as per the error message.
I want to capture the parameters to test SP execution in a new query window, manually. We do not have an SSDT tool in the client environment with which to debug the SSIS package to identify parameters, however we have imported the ssis package in SSMS.
Is there any way I can capture the parameter passed at runtime to SP via the ssis package in SSMS?
This one is easy as you can write code in the SP which you want to debug :
1- Create a table for variable capture
2- in procedure just give insert statement like
Insert into dbo.VariableLog values (#param1 , #param2 )
You can turn on sql server profiler and capture the queries being run againt the database when SSIS package is executed, there you can see what parameters being passed in.
Modify your sp to capture the parameters before doing further processing. Like this :
CREATE TABLE dbo.ProcParameters
(
SeqNo int identity(1,1),
ProcNm VARCHAR(255),
Param1 nvarchar(255),
Param2 nvarchar(255),
ExecResult NVARCHAR(MAX),
ExecTime DATETIME DEFAULT(GETDATE())
)
create procedure MyProc
(
#Param1 nvarchar(255),
#Param2 nvarchar(255)
)
as
begin
declare #Id int,#ExecResult NVARCHAR(MAX)
insert into ProcParameters
(
ProcNm ,Param1 ,Param2
)
VALUES('MyProc',#Param1 ,#Param2)
select #id = ##identity
begin try
/*
Your Code goes here
*/
SET #ExecResult ='Success'
end try
BEGIN CATCH
select #ExecResult = ERROR_MESSAGE()
END CATCH
UPDATE ProcParameters
SET ExecResult = #ExecResult WHERE SeqNo = #id
end
Now, each time the proc is being executed, the values will be stored in the table ProcParameters and you can get it from there. Also, the result of each execution can be found in the column ExecResult.

MS SQL Linked Servers And Using In FROM Clause

I have a very basic test stored procedure, shown below. This proc is reading data in a different database, in a different server. To do this I am using a linked server. From what I have read, I need to change the FROM clause to this:
[linked server name].[database name].[schema name].[table name]
However, I would like to pass in the linked server name and database name as parameters and use them in my FROM clause. I am not concerned with injection attacks, etc. I will be passing this in from a config file.
create PROC [dbo].[SelectTEST]
#GU UNIQUEIDENTIFIER,
#LINKED_SERVER_NAME nvarchar(max),
#DATABASE_NAME nvarchar(max)
AS
SET NOCOUNT ON
SET XACT_ABORT ON
BEGIN TRAN
SELECT [GU]
FROM '[' + #LINKED_SERVER_NAME +'].['+ #DATABASE_NAME + '].[Test Table] '
WHERE ([GU] = #GU OR #GU IS NULL)
COMMIT
This is a big mess of syntax errors. Is it possible to pass in these parameters and use in my stored procedure? I would have to make this change to a bunch of different procs, so sorta trying to find the a succinct solution...

Using variables inside Execute SQL task query

I am a complete beginner in terms of SSIS packages.
I really want to execute a stored procedure that takes in parameters with different values at each iteration of the foreach loops. So I'm wondering if anyone can give me an example (VERY VERY VERY basic example) on how I can use variables as values inside an Execute SQL Task like this:
UPDATE tbName SET c1 = Var1, C2 = Var2 etc...
OR
#bDate = VarDate1
#eDate = VarDate2
where Var2, VarDate1, VarDate2 are variables in BIDS
First you need to create the stored procedure on the SQL Server end. This is done with a statement like this. After this has been ran a new stored procedure object called "yourProcedure" will exist in the database.
CREATE PROCEDURE yourProcedure
#pKeyVar int, /* declare variables to be passed here */
#pFirstVar varchar(40),
#pSecondVar int,
#pThirdVar decimal(18,2)
AS
BEGIN
Update yourTable Set /* place what will be done here */
Col1 = #pFirstVar,
Col2 = #pSecondVar,
Col3 = #pThirdVar
WHERE KeyColumn = #pKeyVar
END
GO
Once the stored procedure has been created you can call it like this:
exec dbo.yourProcedure 12345, 'string value', 2, 2.05
There are a couple ways to call it from SSIS, but the most common is the Execute SQL Task. You can map the parameters that will be passed to the variables that hold the content and put the task inside your looping logic.
Here is a decent walkthrough of the Execute SQL Task.
Pay close attention to the section on mapping parameters to variables etc. The version of SSIS is 2005 but the concepts are all the same.
Update after comment.
In order to loop through a recordset and obtain values to pass back to the proc you can follow the information as provided in this article.

could any one help me finding the Error with SP

create function Fun12(#InsCd varchar)
returns varchar(100)
as
begin
declare #ret varchar(52)
set #ret = (select [InsName] from [Assignment4].[dbo].[1466]
where rtrim(ltrim([InsCd]))= #InsCd)
return #ret
end
Executing:
declare #r varchar(50)
exec #r = dbo.Fun12 '436'
select #r
I am getting NULL value.
Could any one please help me finding the error?
You need to specify a size for your parameter #InsCd.
Some thing like this but you might want to use another value than 20 depending on the size of field InsCd.
create function Fun12(#InsCd varchar(20))
First, you should make sure that the code contained by the function actually returns something when you run it directly in SQL Server Management Studio (SSMS):
-- SQL
select InsName from [1466] where rtrim(ltrim([InsCd])) = '436';
In this case, I would use a stored procedure rather than a function. You could also use the SSMS Profiler (Tools > Profiler) to monitor the traffic to SQL Server. This way, you can actually see what gets executed, see the parameters for SPs, etc.