March 24, 2016 at 9:35 am
How can I return
select @@servername along with the result of this stored procedure - msdb.dbo.sp_get_sqlagent_properties
in a single row.
Result : Servername1,all columns from above store procedure (msdb.dbo.sp_get_sqlagent_properties)
I cannot create any temp tables or additional stored procedures and I need to run the query on a list of sql servers in an SSIS package inside a for each loopl container.
Thanks
March 24, 2016 at 9:42 am
Those somewhat contrived requirements make this sound like a homework assignment. Why can't you create any temp tables or new procedures?
John
March 24, 2016 at 9:50 am
John Mitchell-245523 (3/24/2016)
Those somewhat contrived requirements make this sound like a homework assignment. Why can't you create any temp tables or new procedures?John
This is actually a common business requirement. The way I like to do it is to:
1. Get two monitors
2. Run the select @@servername query on one monitor
3. Run EXEC msdb.dbo.sp_get_sqlagent_properties on the second monitor
4. Push the two monitors together so as to appear that the result set is one really wide row
-- Itzik Ben-Gan 2001
March 24, 2016 at 10:49 am
I can think of 3 possible solutions. The first one is to use a table variable.
March 24, 2016 at 10:57 am
Why no temp tables? The normal solution would be to EXEC into the temp table, then query it.
Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability
March 24, 2016 at 1:13 pm
I like Alan's solution, but I'd never want to move my monitors; I'd move the windows instead. 😛
Seriously, why the restriction on temp tables?
March 24, 2016 at 3:01 pm
... that way I can tell my boss that second monitor really is required!
March 24, 2016 at 8:54 pm
Apologies to disappoint people on board for their 'humour'. But that is not the case.
I need to extract the result from the stored procedure from a bunch of servers along with their respective server names.
The code will be part of an SSIS package which will loop through the servers in a for each loop and I cannot create any DB objects on any of the servers.
Temp tables are allowed but I wanted to know if it can be achieved without their use.
Thanks
March 24, 2016 at 8:58 pm
Thank you
March 24, 2016 at 9:29 pm
sqlnewbie17 (3/24/2016)
Apologies to disappoint people on board for their 'humour'. But that is not the case.I need to extract the result from the stored procedure from a bunch of servers along with their respective server names.
The code will be part of an SSIS package which will loop through the servers in a for each loop and I cannot create any DB objects on any of the servers.
Temp tables are allowed but I wanted to know if it can be achieved without their use.
Thanks
Getting an extra column into the same resultset the procedure delivers is a pain in T-SQL. You know the server name because you're querying it from SSIS so can you simply add the column to your pipeline in your Data Flow Task using a Derived Column Transformation?
There are no special teachers of virtue, because virtue is taught by the whole community.
--Plato
March 25, 2016 at 6:47 am
I like Orlando's idea, but here are some other options:
Use a Central Management Server. If you're going to do this manually, you could actually just register the servers in SSMS in a group and query the group.
You could script the procedure and add the column. The procedure shouldn't change unless different versions are queried and even then the probabilities are low.
USE msdb;
EXEC sp_helptext sp_get_sqlagent_properties;
If you script the procedure, remove all the inline comments or convert them to block comments. Otherwise, you'll comment everything after the first comment.
March 28, 2016 at 4:35 am
Thanks...That is one of the solutions but was curious to know if I could do using only t-sql.
Anyways thank you for the response.
March 28, 2016 at 8:30 am
sqlnewbie17 (3/28/2016)
Thanks...That is one of the solutions but was curious to know if I could do using only t-sql.Anyways thank you for the response.
As I mentioned I would use SSIS here for simplicity but as with most tasks T-SQL can also be used. This technique could help:
http://www.sqlservercentral.com/articles/T-SQL/138306/[/url]
There are no special teachers of virtue, because virtue is taught by the whole community.
--Plato
March 28, 2016 at 10:39 pm
Noted and thank you again !
Viewing 14 posts - 1 through 13 (of 13 total)
You must be logged in to reply to this topic. Login to reply