[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

MS SQL REPORTING 2000 - Changing Commandtext during runtime

Posted on 2006-11-25
9
Medium Priority
?
432 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
6 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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
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

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Hi, In my previous Article  (http://www.experts-exchange.com/Database/Reporting/A_15199-Introduction-to-Microstrategy.html)I discussed some basic understanding of Microstrategy that how we can get in Intro of Microstrategy (MSTR). Now it's tim…
Hello, In my precious Article  (http://www.experts-exchange.com/Database/Reporting/A_15280-Create-Project-in-Microstrategy-Part-I.html)we saw the Configuration part for Microstrategy which included Metadata Creation and DataSource Preparation as …
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
As many of you are aware about Scanpst.exe utility which is owned by Microsoft itself to repair inaccessible or damaged PST files, but the question is do you really think Scanpst.exe is capable to repair all sorts of PST related corruption issues?
Suggested Courses

873 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