I have many RDLC reports based on a StoredProcedure dataset on SqlServer.
My StoredProc have an OUTPUT parameter which receive an XML string with a list of ids to filter my table <ListXML><ItemId>10</ItemId><ItemId>11</ItemId></ListXML>.
I also want to show on my report header the formatted list of ids so users can see what they sent 10, 11.
So far, i'm handling the case with a CustomCode in the report properties using the System.Xml reference but i don't like having to use an external reference (especially while deploying the report on the server), the overhead of copy-pasting the code in each and every report and i'm concerned that my team will forget to copy the custom code and develop other solutions to handle the problem. I'd rather have my StoredProcedure return me the formatted string of Id to display on my report header.
i tested the case with a dummy sp
CREATE PROCEDURE [dbo].[Rep_Test]
#test VARCHAR(20) OUTPUT
AS
BEGIN
set #test = 'hello'
select top 10 * from item
END
and it revealed to me that it doesn't work right of the bat. Visual Studio does set 'Hello' as 'default value' to my parameter in the report but if i give a value to my report parameter it will not be overidden by the stored procedure.
Any insight on the subject or any other solution to handle the problem would be greatly appreciated
No. An RDLC cannot handle OUTPUT parameters in its dataset. You have to use a workaround.
One workaround is to employ a wrapper procedure that reads the resultset of the inner procedure, and adds another column with the value of the output parameter in every row.
A more detailed description with code can be found here.
Related
I have copied text from a stored procedure (SP) in SQL Server and modified it and created a new stored procedure with a new name (Example spMyproc to spMyProc_a). I then updated a report in Crystal Reports that was using the original SP as its data source and substituted the new SP. However, the fields/formulas are still referencing the original SP.
Is there an easy way to remap the fields/formulas to reference my new data source? Or, will I need to update each one individually? Also, I cannot expand my new data source in the Field Explorer tree view. Am I doing something wrong?
In Crystal;
1. Select Database Menu
2. Set Datasource Location
3. Choose your current SP
4. Select "Replace with:" SP
5. Select Update and provide any parameters
6. Update the SP name in Field Explorer under Database Fields
OR;
In SQL create a dummy SP that executes the actual SP with the same parameter definitions.
In your report use the first SP as the datasource.
When you need to update the actual SP just modify the dummy to call the new SP. As long as the parameters and field definitions are the same there is no need to modify the report otherwise see above.
I have the following stored procedure in an SQL Server database...
create procedure SupportTicketsFullTextSearch
#SearchText varchar(1000)
as
begin
select ID, k.rank
from SupportTicketsSummaries st
inner join freetexttable(SupportTicketsSummaries, (ShortSummary, Description), #SearchText) as k on st.ID=k.[key]
order by rank desc
end
I want to use this from Entity Framework, but when I try to add a function import, if I click the button to get the column information, I get the message "The selected stored procedure or function returns no columns"
I've done some searching, and seen a lot of people with the same problem, but they all seem to be using dynamic queries or temporary tables. My query doesn't use either (as far as I am aware anyway), and I can't find any advice that helps.
I tried adding...
SET FMTONLY OFF
...at the beginning of the SP, but it didn't help.
Anyone any ideas how I can import this SP as a function?
Never found out why the import wizard couldn't see the schema, but it turned out to be really easy to fix.
All you need to do is open the model browser, right-click on the Complex Types node, and add a new complex type that has properties that match the columns returned by your stored procedure. Make sure the names match exactly.
Then start the function import wizard, choose complex type, and pick the one you just created from the drop-down list.
Hope this helps someone.
I have a stored procedure named "OUTPUT_DATE" that takes in a date, and then outputs the date in the standardized format specified in another section of the database.
I am currently working on creating a BIRT report using this, however would like to call this stored procedure while getting the data to format a specific column of data. My question is, is it possible to call a stored procedure on my select statement, or is there another method to do this using BIRT?
I am already aware of the functions build into BIRT to output specific date formats, but this does not currently work the way I want since our date format is specified in the database.
My preference would be something similar to this...
SELECT col1, col2, OUTPUT_DATE(dateCol) FROM the_table
You can, but you should create a user defined function (scalar valued) instead of your stored procedure - functions can be called the way you want to.
Document & sample from Microsoft
I have a stored proc in sql-server and one of the parameters it returns is a string with the query parameters. I display those query parameters at the top of the report. That works great if something is found, not so great if nothing was found.
We have tried returning two query results, one the data set that I will make the report from (which includes the query parameters), the other the query parameter string. Crystal appears to only see the first data set, and this very old discussion (http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=42462) says that is not something that will work. But that was over 5 years ago, and I'm hoping things have changed.
The problem, is if nothing is returned, the report is so blank that the person doesn't even know what query parameters they used. If they could see that they queried something that doesn't return any results, that would be useful.
So, if I have at the end of my stored proc:
SELECT * FROM [#ResultSet]
select #SearchCriteria as SearchCriteria
I'd like to be able to display the SearchCriteria even if there is nothing in the #ResultSet. Can it be done with this version of Crystal? Is there another way to do this?
Unless as stated by the first answer the results of one procedure have the same number of columns of another procedure (this includes type), if this is the case you can UNION the results or UNION ALL the results (if you want duplicates) to get ONE resultant set.
If the types or columns are not the same then you cannot do this. The only other option you can do is to merge all the relevant data into a temp table and then return the results from that temp table (SELECT * FROM #temp)
How are you currently able to display the parameters when results are found?
You haven't mentioned how you are using the Crystal Report in your environment.
Typically, I've done criteria display by passing the parameters to the Crystal Report as Report Parameters, and then using them in fields. This assumes you are calling it from a client application in some way.
Another option is to load the results into client datatables and binding to that as a datasource, it's certainly possible to handle the multiple result sets that way.
I am having one situation,
Book Number | Book Authors | Publications | Versions
Controls i used in above fields, label in Book No., Combo box in Book Authors, Label in Publications and Combo box in Versions.
The above is my UI, if i choose the book authors from the combo box(values in combo box are retrieving from db), the values of publications and versions should retrieve from the db based upon the item i choose from the combo box. The page should not refresh. How to write the stored procedure for this.
It seems like you really are asking the wrong question. There are a couple good answers here for how to write a select statement (via a stored procedure, or not).
However, getting the data from the database has little to do with to putting that data into the appropriate controls on your UI, and nothing to do with making sure the page does not refresh.
If you are really interested in how to how to write a stored procedure for a simple select statement, accept #MikaelEriksson's answer, but add appropriate SET statements to minimize future upgrade issues. You will also need to modify the column and table names to reflect your actual data (of course).
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE GetBooksByAuthorID
#AuthorID int
AS
BEGIN
SELECT B.BookName,
B.BookID
FROM Books as B
WHERE B.AuthorID = #AuthorID
ORDER BY B.BookName
END
GO
If you are interested in how to bind the data to your UI, and how to do it without refreshing the UI; then you need to ask a new question about that. It should be specific to your web framework. Generally speaking, if you want web UI update without refresh, you will be using some form of AJAX.
If what you're trying to do is just cascading boxes, you write a SELECT query that return the appropriate rows. This is not what a stored procedure does.
SELECT * FROM `books` WHERE `author_id` = [author_id]
Stored procedures are used to process data, not select it.
Check this Sites to Start of:
HOW TO: Call a Parameterized Stored Procedure by Using ADO.NET and Visual C# .NET
Calling Stored procedures in ADO.NET
The C# Station ADO.NET Tutorial
Regards
This is how you write a stored procedure that will fetch something for you. I have of course no idea what output you want and what parameters you need so ...
create procedure GetBooksByAuthorID
#AuthorID int
as
select B.BookName,
B.BookID
from Books as B
where B.AuthorID = #AuthorID
order by B.BookName