Crystal Reports not showing stored procedure outputs - sql-server

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.

Related

Best way/practices to generate multiple result sets in stored procedure to different tabs in Excel

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.

select the result of stored procedure

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..

passing multiple values to SQL procedure parameter from vb6

I have a slight problem with getting records in my report made in vb6.
my stored procedure looks like this
create proc sp_rpt
(#area varchar(20),
#type varchar(20) )
as
select * from tableA where (area=#area) and type in (#type)
That is what i tried, but i do not get my records.
although if i replace #type with 'Commercial','Domestic' in SQL server itself i get perfect results.
The string being passed from vb6 is in this form 'Commercial','Domestic'
i have a variable in vb6 named categories .
categories="'commercial','Domestic'"
if you have an idea on how i should go about this please help.

SQL Server : 2 Stored Procedure 1 for XML & one for data

I have 2 systems that use the same stored procedure.
The problem is that one system needs data as normal select statement inside the stored procedure, while the other needs the data in XML format
I just looking for best practice,
do I have to create 2 stored procedures so each system read from its own stored procedure?
or I create one stored procedurefor normal data and the other stored procedure read data from the first one and fill it in temp table using OPENROWSET?
or add a parameter for data output so if I want data i pass 1 if I want xml I pass 2?
any other suggestions?
Thanks
Depends on the details of the stored procedure but as a rule of thumb I prefer to add a parameter to determine the output type. In this way you will avoid to maintain two procedures and the risk of going out of sync at some point in the future.
I would suggest Two Stored Procedures. as using OPENROWSET might have some performance issues.
When you say you need data in XML format, this query will look very different from the query which returns data in rowset and both queries will have a very different execution plan.
So if you decide to embed this non-XML procedure inside a OPENROWSET query and then try to pull XML OUTPUT from that query might result in a very inefficient query plan.
I would say simply create Two Separate procedures and have two separate Execution plans for each procedure which can possibly result in a better performance.
Another Option that comes to my mind is that you can add a Parameter to your Procedure like #XML_OUTPUT and at run time check the value of Parameter and run respective queries, something like this...
CREATE PROCEDURE Get_DATA
#Param1 DataType,
#Param2 DataType,
#XML_OUTPUT BIT
AS
BEGIN
SET NOCOUNT ON;
IF (#XML_OUTPUT = 1)
BEGIN
SELECT *
FROM TABLE
FOR XML PATH('')..... bla bla
END
ELSE
BEGIN
SELECT *
FROM TABLE ... bla bla
END
END
And at run time if #XML_OUTPUT was set to 1 , the procedure will return XML Data, else it will return non-xml data.

SQL Server stored procedure issue calling another stored procedure

Here's a issue I have with a stored procedure (using SQL Server 2005), inside this stored procedure it calls another stored procedure putting the data into a temp table.
INSERT INTO #tmpTable (Column1, Column2, Column3)
EXEC psp_rptInsideStoredprocedure 2
This inside stored procedure has a mode parameter that determines which columns get passed out. In this mode (Mode2) only 3 columns get passed out, when this inside stored procedure is used for another report (Mode1) 4 columns gets passed out. Sometimes the parent stored procedure complains about trying to insert the 4 column and sometimes not.
I know it's always passing in mode 2 but it's like SQL Server knows that sometimes this stored procedure has passed back 4 columns.
Any thoughts on a solution?
Thanks
Don
Make the child procedure always return the same number and type of columns, use NULL if necessary. If the results are so different for the two versions, that you can't combine them like this, you should consider making two different procedures.
I'm just guessing at your procedure, but you could create a #ResultSet temp table and populate it based on your type parameter, but always return all columns, etc. If you are returning lots of rows this becomes bad, as the temp table is overhead. in that case, just make sure your result sets return the same number of columns:
IF #version=1
BEGIN
SELECT col1, col2, NULL FROM ... WHERE ...
END
ELSE
BEGIN
SELECT col1, col2, col3 FROM ... WHERE ...
END
Then when both parents call it, accept all the columns, but they can ignore what they don't need.
Daisy chaining stored procedures is generally not a great idea. I would remove the call to the sproc and type out the t-sql for exactly what you need. If your really set on calling another sproc. Make a new sproc that does exactly what you need for this one situation.
It's all about the Single Responsibility Principle

Resources