Link 2 store procedures in 1 crystal report - stored-procedures

Crystal Reports
Hi,
In a report called ICD_PrivateHospital, I have designed to show output to two table from two stored procedures.
1st stored proc: usp_RPT_Private
2nd stored proc: usp_RPT_Private2.
I have created both the stored procs and it is executing successfully. I also have designed the Crystal Report in Visual Studio 2008. I have added both the stored procs in the crystal report with no error.
I only want to show the top 20 records. It is running successfully when I add the fields and parameters from the first stored procedure, but when I add the 2nd stored procedure's fields into the report, duplication occurs for both the results in stored proc 1 and stored proc 2.
How can I solve this issue?

check the linking? because of linking can be the issue.. if you are not sure of the linking then check the option select Distinct Records to eliminate the duplicate records.

Related

SQL Server 2014 - Stored Procedure to perform conditional checks on a table

I'm new to SQL and I have imported several .csv files that I have joined in SQL Server. I will be using SSIS packages to automate these imports.
I wanted to create a stored procedure to perform a series of checks on one of these tables and populate a column that I have listed as a flag.
The check performs a comparison of two columns already within the database table.
One check is a condition where I would like to compare two price columns to see if the variance between the two is greater than 50%. If so, then I'd like to populate my flag column with a 1, if not, then 0.
I'm not really sure where to start. Any suggestions or examples that you may have would really help me out. Thanks!

RDLC create table without Dataset

I have refereed this Question which is same like this but it is not active and doesn't include solution.
I have a MVC application in which i can generate blank report in pdf format.I have a Report_Name.rdlc report file and added a Table just to see how it looks when i generate report. I don't have any data set so i cancelled option asking for dataset.
Now it gives me error :
Error 3 The tablix ‘Tablix8’ is in the report body but the report has no dataset. Data regions are not allowed in reports without datasets.
I don't want any dataset to bind with my table. i just want to make a table in rdlc report & run my mvc application to see how it looks.
any suggestion ?
You have to assign a dataset to a tablix, there is no way around it. Just create a dummy dataset that only returns one field with no data; maybe the SQL could be SELECT GETDATE() AS blah (if you are using SQL Server). Set the dummy dataset as the dataset for the tablix, and do what you need to with it.

How to Store an Aggregated Value in a Stored Procedure?

I am using SQL Server 2012 and trying to write a stored procedure that will have two components:
1. Select statement that will return several rows
2. Another component will have an aggregated value based on some conditions.
So, for the second component, I am thinking to declare a variable in the stored procedure and store the aggregated data there.
Now, my question is can I populate my output parameter with the data stored in previously declared variable and access the parameter from SSRS 2012?
I would appreciate any suggestion(s) to get me started.
Thank you

Avoiding round-trips when importing data from Excel

I'm using EF 4.1 (Code First). I need to add/update products in a database based on data from an Excel file. Discussing here, one way to achieve this is to use dbContext.Products.ToList() to force loading all products from the database then use db.Products.Local.FirstOrDefault(...) to check if product from Excel exists in database and proceed accordingly with an insert or add. This is only one round-trip.
Now, my problem is there are two many products in the database so it's not possible to load all products in memory. What's the way to achieve this without multiplying round-trips to the database. My understanding is that if I just do a search with db.Products.FirstOrDefault(...) for each excel product to process, this will perform a round-trip each time even if I issue the statement for the exact same product several times ! What's the purpose of the EF caching objects and returning the cached value if it goes to the database anyway !
There is actually no way to make this better. EF is not a good solution for this kind of tasks. You must know if product already exists in database to use correct operation so you always need to do additional query - you can group multiple products to single query using .Contains (like SQL IN) but that will solve only check problem. The worse problem is that each INSERT or UPDATE is executed in separate roundtrip as well and there is no way to solve this because EF doesn't support command batching.
Create stored procedure and pass information about product to that stored procedure. The stored procedure will perform insert or update based on the existence of the record in the database.
You can even use some more advanced features like table valued parameters to pass multiple records from excel into procedure with single call or import Excel to temporary table (for example with SSIS) and process them all directly on SQL server. As last you can use bulk insert to get all records to special import table and again process them with single stored procedures call.

MSSQL2000: Using a stored procedure results as a table in sql

Let's say I have 'myStoredProcedure' that takes in an Id as a parameter, and returns a table of information.
Is it possible to write a SQL statement similar to this?
SELECT
MyColumn
FROM
Table-ify('myStoredProcedure ' + #MyId) AS [MyTable]
I get the feeling that it's not, but it would be very beneficial in a scenario I have with legacy code & linked server tables
Thanks!
You can use a table value function in this way.
Here is a few tricks...
No it is not - at least not in any official or documented way - unless you change your stored procedure to a TVF.
But however there are ways (read) hacks to do it. All of them basically involved a linked server and using OpenQuery - for example seehere. Do however note that it is quite fragile as you need to hardcode the name of the server - so it can be problematic if you have multiple sql server instances with different name.
Here is a pretty good summary of the ways of sharing data between stored procedures http://www.sommarskog.se/share_data.html.
Basically it depends what you want to do. The most common ways are creating the temporary table prior to calling the stored procedure and having it fill it, or having one permanent table that the stored procedure dumps the data into which also contains the process id.
Table Valued functions have been mentioned, but there are a number of restrictions when you create a function as opposed to a stored procedure, so they may or may not be right for you. The link provides a good guide to what is available.
SQL Server 2005 and SQL Server 2008 change the options a bit. SQL Server 2005+ make working with XML much easier. So XML can be passed as an output variable and pretty easily "shredded" into a table using the XML functions nodes and value. I believe SQL 2008 allows table variables to be passed into stored procedures (although read only). Since you cited SQL 2000 the 2005+ enhancements don't apply to you, but I mentioned them for completeness.
Most likely you'll go with a table valued function, or creating the temporary table prior to calling the stored procedure and then having it populate that.
While working on the project, I used the following to insert the results of xp_readerrorlog (afaik, returns a table) into a temporary table created ahead of time.
INSERT INTO [tempdb].[dbo].[ErrorLogsTMP]
EXEC master.dbo.xp_readerrorlog
From the temporary table, select the columns you want.

Resources