I have result of stored procedure which is using dynamic pivot.
I need to select the result, because I want to create rdlc report.
In RDLC, it's using select at dataadapter, but I have a problem with that because I used pivot stored procedure.
Can you help me with this issue, how to select the result of stored procedure, which the fields are dynamic.
Thank you..
Related
I have a report with a lot of datasets, and I want to make it easy for maintenance. I created a stored procedure that runs multiple select statements and accesses the data with parameters.
Sample stored procedure:
CREATE [dbo].[sp_test_report]
#inputReportPart varchar(20)
AS
BEGIN
IF (#inputReportPart = '1' OR #inputReportPart = 'debug')
BEGIN
SELECT a, b, c
FROM table1
END
IF (#inputReportPart = '2' OR #inputReportPart = 'debug')
BEGIN
SELECT q, w, e
FROM table2
END
END
But when I implement it to SSRS, the default column always use the first query even the parameter value is different.
Result:
Dataset view
Dataset1 property
Dataset2 property
I try to rebuild solution, refresh field, and delete .rdl.data but it doesn't work
Any solution other than add the column manually into dataset?
i want to make it easy for maintenance then i created stored procedure that store multiple select
That won't make anything easier. Use a different stored procedure for each dataset.
SSRS doesn't actually run your procedure to determine the dataset schema. So it will always discover the first resultset in the procedure, whether it uses FMTONLY or the newer sp_describe_first_result_set.
If you really wanted to make this work you'd have to add WITH RESULT SETS to your Dataset query which enables the client to specify the resultset metadata.
I'm looking to call a stored procedure on SQL Server via Excel. The reason I'm using Excel is because there are values being input by users which get passed in as parameters to the stored procedure and executed to return the resulting datasets in a new data tab. However, the stored procedure has about 6-7 select statements responsible for generating 6-7 result sets. Aside from creating separate stored procedures for each result set, which isn't feasible as its timely and the result sets build upon each other, what is the best way to handle this or solution to look into? Is it something I need to build into the logic of the stored procedure or something I can configure in Excel?
My stored procedure would look something like this to give you an idea
CREATE PROCEDURE Test
AS
BEGIN
SET NOCOUNT ON;
SELECT TOP 10 PersonType,NameStyle,Title
FROM [AdventureWorks2016CTP3].[Person].[Person]
SELECT TOP 10 PersonType,Firstname,Lastname
FROM [AdventureWorks2016CTP3].[Person].[Person_json]
SELECT ****
.
.
.
SELECT ****
END
GO
In the stored procedure give same column names to all the select statements and use UNION between them and then have an additional column to each select statement to identify which table the data is coming from, ideally use table name.
Then call the stored procedure into a main tab once and then reference that data into other tabs and filter them.
I have a SSRS Report which is using a dynamic SQL Server stored procedure with one parameter only and it works fine.
I want to create a report which whenever I run it, it loop through multiple values for that parameter and creates multiple results, instead of doing that manually.
I found below links from Stack Overflow, but none of them help a lot.
Link1
Link2
I also read some I can use List in SSRS, but I am not sure how to do it in my case.
Any idea?
This might not be an answer as you have not provided enough detail, but I'm sure this idea will help you.
I think you'd better to change your stored procedure to accept multiple values and in your procedure return multiple result sets or combine record sets for each parameter value.
For example, assume you have procedure Proc1, which gets a number as parameter.
create procedure Proc1 (#aYear int)
as
begin
select *
from Orders
where OrderYear = #aYear
end
Now, what you need to do is changing your procedure to accept multiple years (for instance as a comma separated value)
create procedure Proc1 (#csv_years varchar(100))
as
begin
-- use some function or techniques to split the #csv_years
-- and store it into a temp table #years ([Year] int)
-- now, join your main data with this #years table
select #years.[Year], Orders.*
from Orders
inner join #years on #years.Year = Orders.OrderYear
end
Now, your are returning the result for multiple years and you can show that in your report by grouping on [Year] column
You need to use data driven subscription. I had cases with dynamic parameters and the only solution was data driven subscription.
I have a stored procedure with the following format :
CREATE PROCEDURE proc_test
#variable1 int
AS
SELECT column1, column2, ....
FROM table_test
Because this procedure doesn't return any values explicitly, it's difficult to know how many lines of results have been returned. What's more, I cannot modify this stored procedure since it's created by another programmer and already used in the application.
So my question is, if I want to get the resultset generated by the select statement, how can I do it ?
After fired the procedure you can try use a session variable ##rowcount:
select ##rowcount
I'm not sure, maybe it will help you.
I created a stored procedure in SQL Server. It works fine there.
When I call it from Crystal Reports, it shows parameters fields but it does not show the outputs in database fields. Actually it shows the stored procedure in database fields but not the output fields or + sign beside the stored procedure.
Here is the codes in stored procedure:
CREATE PROCEDURE [test]
#mcode char(10),
#zcode [int],
#odolmas[float]=0 output,
#gmas[float]=0 output,
#vmas[float]=0 output
AS
set #gmas=0
set #vmas=0
set #gmas=9
set #vmas=5
set #odolmas=((#vmas-#gmas)/2)
GO
In Crystal Reports I can see the #mcode and #zcode as input parameters. But I cannot see #gmas, #vmas and #odolmas as outputs.
Please help me do it and because I am not professional please say it step by step what should I do
Thanks
When we execute the stored procedure shown in your question, we won't get any output. Try using the select statement inside your stored procedure, the return values will be seen by crystal report.
Say for example Select #gmas as Col1, #vmas as Col2 in your procedure at the end, may show the fileds as col1 and col2. You can place these col1 and col2 on your report for display purpose.