Solved

MS SQL REPORTING 2000 - Changing Commandtext during runtime

Posted on 2006-11-25
9
410 Views
Last Modified: 2008-03-04
I need to change the commandtext of a report during runtime because my parameters are too complex. The query to be sent to the report is the result of a front end (ASP.neT) query builder which has atleast 10 selection criteria.

sql="select <fieldlist> from view where 1=1"

sqla=" and f1 in (fx1,fx2,fx3....)"
sqlb=" and f2 in(fy1,fy2,fy3...)"

sql=sql & sqla & sqlb

and so on.  

One way could be to getreportdefnition for the report, save it as an XML file, modify the command text on the file and then createreport back on the report server.

IS there any other way I could achieve this?

kalrani
0
Comment
Question by:kalrani
  • 4
9 Comments
 
LVL 18

Expert Comment

by:chrismc
ID: 18118678
10 parameters is not a big deal for RS, looks horrible on the selection but it could work.
And parameters selection options can be tied to previous parameter selections, simply by including the parameter name in the where clause of the dataset for the second parameter. The second parameters list won't get populated until the first is parameter is selected.

Secondly, building SQL queries on the fly as you have in your example, is not efficient as the command has to be compiled at run-time. The more complex the query, the more of an issue this becomes.
Try and put as much of the SQL in a stored procedure to which you can pass parameters (NB: multi-valued parameters can't be passed to stored procs though!). Stored procedures are pre-compiled and run much faster. If you still feel it's too complex to fit into one routine, put it into several procs, then in RS, using standard SQL call the appropriate proc, e.g.;

If @Param1 = 'Red'
    Exec procRed @Param2

If @Param2 = 'Green'
    Exec procGreen @Param3, @Param4

For multi-valued parameters, consider using views. Again these are pre-compiled queries but you can use them as a table in a query. E.g.;
   Select * From vwABC Where Field1 In (@Param7)

Where vwABC would be

Create View As vwABC
As
  Select Field1, Sum(Field2) From Table1 Group By Field1
Go

This shows the view doing some totalling work so RS doesn't have to.

I have done some very complex reports in RS over nearly 3 years now and have been able to achieve everything within standard RS. The trick is to make SQL do the hard work. Use views and stored procedures to do as much of the work as possible.

Cheers
Chris
0
 

Author Comment

by:kalrani
ID: 18120714
The requirement was such that the end user wanted to be provided with 10 multiselect options to generate reports.

We used a stored procedure with a text parameter. And withing the SP we called the view that joins all the necessary tables for the Report.

We made a front end ASP.net query builder that allows the user to select any combination of paramters from the multiselect list boxes etc, and this query builder provides the where condition in a text string. This text string when passed to the stored  procedure as the text parameter, helps to return matching records from the view.

Works!
0
 
LVL 18

Expert Comment

by:chrismc
ID: 18123209
Hi Kalrani,
As we say,  there is more than one way to skin a cat!
If it works, that's fine.
But I was pointing out that passing snippets of SQL as strings to build up a full query string is highly inefficient. If you are dealing with many tables and/or lots of data, then you will see the problem.
I still think you can use RS and SQL to do all this as standard, without resorting to 'Dynamic SQL'. I understand why you might want another web page as a front end though. But again, multi-select parameters is standard in RS2005 and works well enough.

Let me know if you need me to elaborate.

Cheers
Chris
0
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 
LVL 18

Expert Comment

by:chrismc
ID: 18311291
I did answer the question fully, kalrani just chose not to try it in my view.

Cheers
Chris
0
 
LVL 18

Expert Comment

by:chrismc
ID: 18655316
I've just re-read the thread, it looks like the poster resolved it before I answered. I have no objections to what ever you see fit.

Cheers
Chris
0
 
LVL 1

Accepted Solution

by:
Computer101 earned 0 total points
ID: 18731982
PAQed with points refunded (250)

Computer101
EE Admin
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Problem Statement In an SAP BI BO Integration project when a BO universe is built on a BEx query, there can be an issue of unit & formatted value objects not getting generated in a BO universe for some key figures. This results in an issue whereb…
How to increase the row limit in Jasper Server.
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now