I am working with C# and Crystal Reports library. I have a method that gets the SQL query for a specified parameters as shown below;
pi.GetIndexParameters()))[0].CommandText;
My issue is that once a report has more than one query - how can I find the number of indexes (queries) the report has and return each SQL query then?
//Returns SQL query based on index parameter
public string readSqlQuery(ReportDocument rd)
{
if (!rd.IsLoaded)
throw new ArgumentException("Please ensure that the reportDocument has been loaded");
PropertyInfo pi = rd.Database.Tables.GetType().GetProperty("RasTables", BindingFlags.NonPublic | BindingFlags.Instance);
return ((dynamic)pi.GetValue(rd.Database.Tables, pi.GetIndexParameters()))[0].CommandText;
}
If you need any further information, let me know.
I would do it like this:
// UNNECESSARY, you can skip this
loop through the list and get every value/CommandText, stored in a new list
either concatenate the list into a single string and return it OR
If you're gonna go for 3, i assume you'd want the results from all the queries together?
Then make sure you make a UNION ALL
on your queries...
Example:
SELECT t.id, t.name, t.date FROM table t WHERE <some condition>
UNION ALL
SELECT t.id, t.name, t.date FROM table t WHERE <some other condition>
UNION ALL
SELECT t.id, t.name, t.date FROM table t WHERE <some third condition>
So you're basically concatenating the queries with a "UNION ALL" and get a single result.