I have a need to use the OUTPUT parameter for providing the input to the stored procedure. I tested and found that we can use OUTPUT as INPUT as well.
Is there any limitations / exceptions for this case?
Yes. Number of parameters is 2100. Otherwise no.
Related
I have a procedure that accepts string as input in format dd/mm/yyyy but I need to call this procedure from another application and I am forced to give the format yyyy-mm-dd.
So I have extracted and changed the string to dd/mm/yyyy but the procedure is throwing incorrect syntax error.
Required format: dd/mm/yyyy e.g '11/04/2018'
Input format: yyyy-mm-dd e.g. '2018-04-11'
So my procedure would be
Required format is abcdprocedure('11/04/2018')
My formula
abcdprocedure(SUBSTRING('2018-04-11',9,2)+'/'+SUBSTRING('2018-04-11',6,2)+'/'+SUBSTRING('2018-04-11',1,4))
Error: Incorrect syntax near ''2018-04-11''
I am unable to understand the problem.
Edit
Procedure is being called in below way:
select * from abcdprocedure('11/04/2018')
When you execute a stored procedure within T-SQL, you may supply a value, a variable or DEFAULT for each parameter. You may not supply an arbitrary expression.
Move your expression out into a separate line that places the result into a variable and use that when calling the stored procedure.
(Also, seriously, please reconsider your use of strings here. T-SQL has perfectly good datetime related data types that are designed to hold datetimes. You only have formatting issues because you're working with strings)
EDIT
Procdure is being called in below way:
select * from abcdprocedure('11/04/2018')
Um, no. If that line of code works, then what we're talking about is not what T-SQL calls a stored procedure. Stored procedures are standalone blocks of code and cannot be integrated into larger queries. Again, if this works, please identify what abcdprocedure actually is (a table-valued function?) and update your question.
Documentation says -
A table-valued function returns a single rowset (unlike stored
procedures, which can return multiple result shapes). Because the
return type of a table-valued function is Table, you can use a
table-valued function anywhere in SQL that you can use a table. You
can also treat the table-valued function just as you would a table.
First of all you should check the function 'abcdprocedure'
You can store your conversion from yyyy-mm-dd to dd/mm/yyyy in a variable
Declare #v_date date;
#v_date=SELECT CONCAT( SUBSTRING('2018-04-11',9,2),'/',SUBSTRING('2018-04-11',6,2),'/',SUBSTRING('2018-04-11',1,4));
And then you can call your table valued funcyion
select * from abcdprocedure(#v_date)
you can use below query for this
SELECT CONCAT( SUBSTRING('2018-04-11',9,2),'/',SUBSTRING('2018-04-11',6,2),'/',SUBSTRING('2018-04-11',1,4));
It will work in mysql and sql server both.
OR
SELECT (SUBSTRING('2018-04-11',9,2)+'/'+SUBSTRING('2018-04-11',6,2)+'/'+SUBSTRING('2018-04-11',1,4))
**OUTPUT:**
11/04/2018
I'm just starting developing reports in SSRS and would appreciate some help with this issue if possible! I'm selecting a dataset from a Dynamics database and want to then pass them to a SQL Server stored procedure referenced in another dataset to retrieve data from another database. I have created a report parameter and set it to Allow multiple values and to retrieve its values from a query and set it to the field that I want to retrieve.
The dataset would look like this:
U1234
U5678
U6789
In the dataset that uses the stored procedure I have set up a parameter, #pnum, and in the Parameter Value field I have created an expression using the Join statement like this:
Join(Parameters!pnum.Value, ", ")
When this gets passed to the stored proc it seems to be passing a string formatted like this:
'U1234, U5678, U6789'
Whereas what I would like to achieve is this:
'U1234', 'U5678', 'U6789'
so that I can use them in an IN statement. Is there a way of doing this within SSRS?
Many Thanks!
To anyone else experiencing this issue, the assumption made in the question on how the values are passed to the stored procedure and how they can be used are incorrect.
The value passed from the join expression would be formatted as such, without single quotes at the start and end:
U1234, U5678, U6789
Further to this, when passed to a stored procedure as a single string this can only be used as an in list by using dynamic SQL.
To parse out and filter on the passed values, the string will need to be split on the delimiter and inserted into a table (temporary or otherwise) to be joined to.
A suitable splitting can be found here (though others exist that may better suit your needs) utilising logic as follows:
declare #xml as xml,#str as varchar(100),#delimiter as varchar(10)
set #str='A,B,C,D,E'
set #delimiter =','
set #xml = cast(('<X>'+replace(#str,#delimiter ,'</X><X>')+'</X>') as xml)
select N.value('.', 'varchar(10)') as value from #xml.nodes('X') as T(N)
If you don't have to pass the values to a stored procedure and are using hardcoded datasets (Shared or not) you can actually directly use the parameter value without additional processing either in the query or by adding a join expression to the parameter value in the report:
select cols
from tables
where cols in(#MultiValueParameterName)
You have to add an extra field with the value wrapped in quotes.
Like this:
SELECT field1 AS display, '''' + field1 + '''' AS value
In my stored procedure we have to input the 2013-12-12 to get data. Now with a new system we only want to use month and year to get the correct data. We use Microsoft SQL server 2008.
This is how we get data today:
exec dbo.Month '2013-12-12'
This is how we want the input to be to get data:
exec dbo.Month '2013-12'
-- #dateStr format yyyy-mm-dd
Possible to change?
I don't really know where in the database to start looking, and the stored procedure is to big to start adding here I guess.
There is no type for only a datapart of the date. You can of course change the input parameter to varchar() of some size and then do the necessary format inside the SP with 'Convert' (http://msdn.microsoft.com/en-us/library/ms187928.aspx). But it is not really that nice a solution.
I am trying to retrieve data from one column.
I tried to delimit using
Trim(Mid([RIC_Name],InStr([RIC_Name],"=")+1))
This works for only where "=" is available. I want to do similarly for "."
For example:
.abcdx.fx
werer=lu
jhgjj.nx
Output:
fx
lu
nx
Is this possible in one expression?
If you use the InStrRev function
Trim(Mid([RIC_Name],InStrRev([RIC_Name],".")+1))
you will get the answers shown in the question except for the second one which needs a different delimiter (=).
Depending on the use of this split, you can make the delimiter a variable and assign the appropriate delimiter to it. If you need one statement to crack both delimiters try something like this:
Trim(Mid[RIC_Name],iif(InStrRev([RIC_Name],".")+1<>0,InStrRev([RIC_Name],".")+1,InStrRev([RIC_Name],"=")+1)))
I am using SSRS 2008 R2. And found situation which seems to me a bug.
I have a shared dataset -
SELECT 'value1' AS Value
UNION
SELECT 'value''2'
I bind this DS to multivalue parameter. When I check only value'2 from multivalue drop down - I see that in SQL Profiler such parameter is passed
#Value=N'value''2' -- Two single quotes
When I check both values in profiler I see
#Value=N'value1,value''''2' -- Four single quotes
My Procedure treats first case correctly.
It seems to me that escape happens twice - first for every value, second for whole string?
Does anyone know the source of such behaviour, Thx in advance!
Here is the same thread on MS
I experienced a very similar problem - the weirdest part, as you've seen, is that it worked when one parameter was selected but not for multiple parameters.
Anyway, I solved this by passing the parameter to the stored procedure slightly differently - in the Parameters section of the dataset use the following expression:
=Join(Parameters!Value.Value, ",") substituting your parameter name as appropriate.
This effectively will still pass the same comma delimited string of values but for some reason seems to handle the quotes correctly.