SQL Server Report Parameter - sql

I'm create a SQL Server Report using Business Intelligence tool (visual studio shell 2005) for SQL Server 2008.
I'm calling a stored procedure with 2 parameters. I've tried - Report-> Report Parameter, Added two parameters name them Days and Count.
In the Data panel "command type:text"
exec dbo.DataReport #Days, #Count
error: Must delcare the scalar variable "#Days"
Does anyone know how do get this too work.

Try changing the command type to Stored Procedure, i'm sure its worked for me in the past

If changing the command type to Stored Procedure like was suggested didn't work, try opening the Dataset dialog box and going to "Parameters" tab. Make sure that both parameters ("#Days" and "#Count") are in the list and that each one has a value.

Related

The SQL command requires a parameter named "#SessionID", which is not found in the parameter mapping

I'm trying to execute a stored procedure via SSIS
Error: 0xC0207014 at PO Header, OLE DB Source [59]: The SQL command
requires a parameter named "#SessionID", which is not found in the
parameter mapping.
But as you can see below, the variables are populated, I have mapped the parameters.
So what's going on?
MS SQL 2014
MS Visual Studio 2015
Based on the screenshots, you have mapped variables to parameters. Then just try to delete and recreate the OLE DB Source.
The SQL command requires a parameter, which is not found in the parameter mapping
If it still throwing an error, then use expressions instead of parameters. You can refer to the following link for more information:
Unable to pass a variable value to a stored procedure in ssis
I was having the same issue and even having Visual Studio crash on me. I found that rather than using parameter index of 0,1, 2... I used named parameters in my OLEDB connect and this resolved my error. You must include the # in the parameter name and they must match your sql stored procedure parameter names.
For example instead of [0] and [1] name parameters #StartDate and #EndDate

Declare SQL construct or statement is not supported for simple query

I have simple SQL Query and need to get the input from parameter. I am getting the when i click parameter button. Please let me know how to get the parameter if i have declare statement in my scripts.
Note :OLEDB connection manager used for connection
You can't use parameters in an OLEDB Source if your command contains DECLARE, or anything other than a single SELECT statement.
The way to do what you want is to use build your entire SQL Command into a single SSIS variable, and use the "SQL Command from variable" option in the OLEDB source.
EDIT based on comments:
If you have to handle a SQL Command over 4000 characters, the only way to do it is in a Script Component. The SQL Command in a script component can be any length. Here is an example.

How to invoke stored procs with parameter using T-SQL scripting?

We are using edge-sql to execute T-SQL scripts and also stored procedures via C#. I noticed recently that stored proc support has been added and I'm trying to execute would would be:
exec dbo.sgRouteExportDelete #TripDate='2014-05-06', #RouteId = 1234, #Action='DELETE', #Comment='xxxxxx';
in SQL Server Management Studio, using edge-sql 0.1.2.
I've played around with several variations, but I get one of 2 error messages. Either cannot find stored procedure '' or "cannot find stored procedure 'sgRouteExportDelete #TripDate='2014-05-06', #RouteId = 1234, #Action='DELETE', #Comment='xxxxxx'" The stored proc executes just fine in edge.sql when invoked via C# method.
I did some additional experimentation and found I can execute a stored proc with no parameters: exec dbo.sgVersionGet, but any stored procs with parameters return errors.
So what am I doing wrong? And how could I invoke with parameter values that aren't hard-coded, as above? Both SQL Server and edge use the # character for parsing params.
Any help appreciated ...
-BillyB
In SQL Server when you are referring to a database object without the object full path ([database.schema].object), SQL Server will try to locate the object using the Default/Initial Catalog value which points to the default database if that was not specified within the connection string then chances are that when you try running your statement SQL Server won't be able to find the object throwing the "Cannot find XX" error, You should either specify an initial catalog on your connection string or execute your procedures using the full path, database.schema.procedure E.g. mydatabase.dbo.sp_customerCleanUp. On the other hand there is an internal procedure sp_executesql that you can use to run your procedures without having to hard code the parameters, all you need to do is build a string concatenating the hard coded part of the string (the procedure name) and whatever number of variables you are passing as parameters, see example ( https://technet.microsoft.com/en-us/library/ms175170%28v=sql.105%29.aspx )
The variables are assumed when calling a stored procedure with edge-sql. Any parameter you would preface with an '#' symbol will need to have the same name within the stored procedure.

SSRS Text Query: Variable names must be unique within a query batch or stored procedure

I am developing an SSRS 2008 report, but instead of using stored procedures, I want to use all Text queries. This report was working with stored procedures, but when I changed this report to use same logic but via text queries, I got the following error:
An error occurred during local report processing
    Query execution failed for dataset 'BRSR_Totals'
        The variable name '#END_yEAR' has already been declared. Variable names must be unique within a query batch or stored procedure.
Operation cancelled by user.
The problem is that some of my datasets (text queries) re-use the same parameters and END_YEAR is one of these parameters. How do I make this report run correctly?
One area that you might want to check is case sensitivity. SSRS is case-sensitive when considering parameter names but T-SQL does not have that case sensitivity. Take another look at your code and make sure that all parameters are using the same case.
I just resolved a similar issue using a text query to populate a dataset. It worked in SQL Server Management Studio and it worked in the Query Designer within BIDS, but failed at runtime.
The issue turned out to be BIDS helpfully adding parameters to the Dataset that this query was referencing. Switching to the Parameters tab of the Dataset Properties showed that BIDS had duplicated the parameters I had already added earlier. Deleting the duplicates resolved my problem.
To respond to the suggestion that the logic be off-loaded into a stored procedure: in this case, the report is a custom report for a single customer. The query will only ever be used in this report and makes a few assumptions about the customer's configuration that should not be available globally
I also just fixed this same issue in one of my queries. I was using a text query and had datetime variables/parameters. SSRS added a second set into the parameters for the dataset properties. I deleted them and my query ran fine after that and my graph populated.
I ran into a similar issue on a report where I had declare a substantial number of parameters at the beginning that I didn't want the end user to see. The issue I had was I was using a comma at the beginning of the line, so I had:
DECLARE #Parameter VARCHAR(4) = 'text'
, #Parameter VARCHAR(4) = 'text2'
It worked just fine in SSMS, but when I ran it in Report Builder 3.0 it threw the error shown in this thread. I changed it to remove the comma and to restate DECLARE at the beginning of each line and it worked perfectly.
Check that you didn't declare it twice, once in the CREATE PROC statement you're creating and another in the actual code...I've seen this problem while testing changes to SP code.

User inputs to sql script

I have a SQL Script with the following line
declare #input varchar(20)
Select * from Employees where [dept] =
#input
What I want is When I execute the above script in SQL 2005 I want to prompt for an input By opening an inputbox etc., such that the value is accepted in '#input' variable and so the user retrieves the records giving dynamic inputs.
You can't do that. The database doesn't have a user interface, so there are no means of prompting for a value.
You have to make an application that prompts for the value, queries the database and displays the result.
You're really asking for a nonexistent feature but there are a few workarounds:
SSRS allows you to define a "report" with parameters that will take the form of input boxes etc for your users.
If you're ok with the users using SSMS, create the query as a stored procedure and have them use the execute option in the left-hand tree (this prompts for parameter inputs).
Here's what you want
Accepting User Input
But it's for Oracle( ! ) . I hope this will work for other dbs also
Or use C#; Rapid Application Development Using SQL Server 2005 Compact Edition and Visual C#.NET