question

sand143eep avatar image
sand143eep asked

getting warning when using sp_msforeachdb

Hello All, i am trying to send mail with result set after executing stored procedure which is present in all databases. the code is as follows: > USE msdb > EXEC sp_send_dbmail > @profile_name = 'profiler', > @recipients = 'sanjana.datir@microdef.com', > @subject = 'DB Sizes of mmnc01', > @body = 'The result from SELECT is appended below.', > @query = 'EXECUTE sp_MSforeachdb 'USE [?]; EXEC findingDBsize'' the problem is in the last statement @query here i ma getting the error as Msg 911, Level 16, State 1, Line 7 Database '?' does not exist. Make sure that the name is entered correctly. please help me in formating the query here
sql-server-2008sql
1 comment
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

sand143eep avatar image sand143eep commented ·
even i tried to add a query on @query= DECLARE @command varchar(1000) select @command ='exec madhava' EXEC sp_MSforeachdb @command but no use
0 Likes 0 ·

1 Answer

·
ThomasRushton avatar image
ThomasRushton answered
You've not got enough 's in your last line. @query = 'EXECUTE sp_MSforeachdb ''USE [?]; EXEC findingDBsize''' should do the job.
1 comment
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

sand143eep avatar image sand143eep commented ·
Perfect thanks it worked.
0 Likes 0 ·

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.