Stored Procedures and SSRS 2008 - sql-server-2008

I have a stored procedure in SQL Server 2008 that consists of multple select statements. When building a report in SSRS, I have a dataset that uses that stored procedure. However, the only fields that show up are the ones that are in the first select statement. Is there a way to show the other fields or use multiple select statements within one stored procedure?
Thanks!

Do the selects output the same schema (i.e. fields)? If so, and if you need all the results, you could try UNIONing the separate queries together. Otherwise, why not move the query you need into a new stored proc and call that from the report?

Eric, it's been my experience that when SSRS is based on a stored procdure, the results of the last Select statement are used and not the first. So you should be able to do anything you want up until the last Select statement in the stored proc and then make sure the last Select contains the correct data/columns for the report.

From the MSDN documentation
If multiple result sets are retrieved
through a single query, only the first
result set is processed, and all other
result sets are ignored. For example,
when you run the following query in
the text-based query designer, only
the result set for Production.Product
appears in the result pane:
SELECT ProductID FROM Production.Product
GO
SELECT ContactID FROM Person.Contact

Related

MySQL + SSRS | Stored Procedure only returns one single row

I'm working on several reports for SSRS written in MySQL via ODBC Adapter. For some reason, Stored Procedures only return a single row of data instead of an expected set of data.
Below is the same stored procedure when ran on an SQL Editor:
And below is the stored procedure's execution result when SSRS tries to run it (both on Query Designer and Report Viewer):
I have also set parameters properly as far as i can tell:
so i wasn't able to find an exact answer as to why this happens on SSRS with MySQL via ODBC. What i was able to find was a workaround:
by executing the command as an Expression rather than as a raw query via the Query Editor:
Now the only caveat for this is that the DataSet Fields wouldn't be automatically generated, and that you have to plot them all manually. A good workaround for this is to first run a blank/null query with only the column names (i.e.: SELECT NULL 'column_name_1', NULL 'column_name_2') then later change the query source to Expression. The good thing about using expression is that you only need minor knowledge about how it works and it reduces the confusion with ODBC '?' Parameters.
Cheers!

flow control in MYSQL

I am trying to convert a SQL Server query to MYSQL, but am having trouble with the IF statements. In the SQL Server version, they are used to direct the flow of the query based on a flag, but I cannot get it to work in MYSQL. I have outlined how the code works below:
The script sets a flag based upon how much data can be matched between the query and the database.
It then performs a select statement based upon the flag: if flag=1 select a,b,c where match logic
else if flag=2 select d,e,f where different match logic
I have tried using both IF and CASE WHEN, neither of which work. I would normally have put the IF within the WHERE clause, but different columns are selected depending upon the flag.
Is there a function that will perform IF/ELSE flows MYSQL?
Any help would be greatly appreciated!
Assuming the types and number of columns are compatible, you could do:
select a, b, c
from t
where (v_flag = 1) and match_condition_1
union all
select d, e, f
from t
where (v_flag = 2) and match_condition_2;
The alternative is to use a stored procedure. In MySQL, the if control flow statement is only allowed in programming blocks -- stored procedures, stored functions, and trigger.

Select SQL query FROM table, select using that query?

I'm trying to do the following in SQL alone. In the end it will end up on a wso2 DSS server but if it can be done in sql alone even better :)
Sudocode
Array results=Array;
result = <sql>select id, query from definitions</sql>
foreach result.query
r=<sql>query</sql>
results.push(r)
I am trying to run a select on table a that returns 2 columns.
One of the two columns is named query, and I want to then execute that query returning
id, query_title, query_text
We can assume that the query column always returns the same columns (through aliases written in the query)
The other option would be doing this in WSO2 DSS however I though at least that it can only do what sql does. Maybe joining with the ESB I could get it if that doesn't work but really my goal would be to do it ALL in sql as I am going to insert insert information and then update it into another table anyway.
You cannot do this with a single select query.
One solution is to do this in two steps. Fetch the query in the application using your SQL and then execute the second query from the application.
The second solution is to use a stored procedure and prepare/execute. How you then fetch the results depends on the nature of the results

Show recently executed stored procedures, including parameters

This sql kindly provided by Microsoft lets me see the recently executed stored procedures, but not the values that were passed as parameters.
Where should I look for that information?
SELECT TOP 10
d.object_id, d.database_id,
OBJECT_NAME(object_id, database_id) 'proc name',
d.cached_time, d.last_execution_time, d.total_elapsed_time,
d.total_elapsed_time/d.execution_count AS [avg_elapsed_time],
d.last_elapsed_time, d.execution_count
FROM
sys.dm_exec_procedure_stats AS d
ORDER BY
[total_worker_time] DESC;
That information doesn't really exist anywhere (unless, as others have suggested, you store it yourself). However, you can see it by using SQL Profiler or Extended Events. With SQL Profiler, you need to choose the RPC:Completed and SQL:BatchCompleted events, and make sure that the TextData column is selected for both.
Why not just have you stored procedure insert into someTable on the database.
Something like
INSERT INTO someTable (Value)
SELECT #StoredProcedureInsertParamter

SQL Profiler: who modified a column?

Is it possible to use SQL Server Profiler 2008 to catch which program, run from which computer, is modifying table SALES column POSTED from false to true, but excluding stored procedure 'salesposting'?
I suppose I can use 'objectname' filter for the table, but how to filter the column, the previous value, and the current value?
You could trace specific procedures or update statements through the text data option in the Filters list.
It is likely simpler to add a simple trigger capturing the user / input buffer is likely the best approach.
There is an ApplicationName and Hostname column that you can trace. Just click the check box "Show All columns" that you'll see them
If you want to filter by Stored Procedure, select filter the RPC:Completed event