Find a location of stored procedure

A SQL Server job has called a stored procedure but is there a quick way to check where does this stored procedure located ?

Tks

EXEC      @return_value = [dbo].[CleanDBLog]
AXISHKAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Vikas GargBusiness Intelligence DeveloperCommented:
Hi,

Stored Procedures are stored in  sys.procedures tables of the Database.

select * from sys.procedures
0
Vitor MontalvãoMSSQL Senior EngineerCommented:
Do you want to find in which database is the stored procedure?
Then this code can help you:
EXECUTE sp_MSForEachDB 
	'USE ?;
	SELECT DB_NAME();
    SELECT * FROM sys.procedures WHERE name = ''WriteStoredProcedureNameHere'''

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
AXISHKAuthor Commented:
One more check, how to list all the SQL  jobs ? Tks
0
Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

Vikas GargBusiness Intelligence DeveloperCommented:
Try this

SELECT job_id, [name] FROM msdb.dbo.sysjobs

Open in new window

0
AXISHKAuthor Commented:
Run with error, any idea ? Tks
TSQL.png
0
AXISHKAuthor Commented:
Is It possible to list the active SQL job only ?
0
Vitor MontalvãoMSSQL Senior EngineerCommented:
Verify the quotation. Because it's inside a string you need to duplicate quotations.
Just check with my example. There's two '' before and after the stored procedure name. Then one more for close the string.
0
AXISHKAuthor Commented:
Still not correct,..

EXECUTE sp_MSForEachDB
      'USE ?;
      SELECT DB_NAME();
    SELECT * FROM sys.procedures WHERE name = ''CleanSysDatabaseLog''
0
Vitor MontalvãoMSSQL Senior EngineerCommented:
If you want to know which jobs are running at the moment just run the following query:
select job.name, act.start_execution_date, act.last_executed_step_date, act.last_executed_step_id, act.stop_execution_date
from msdb.dbo.sysjobs job
	inner join msdb.dbo.sysjobactivity act
	on job.job_id = act.job_id
where act.start_execution_date is not null
  and act.stop_execution_date is null

Open in new window

0
Vitor MontalvãoMSSQL Senior EngineerCommented:
AXISHK, you forgot to close the string (last quotation missing):
EXECUTE sp_MSForEachDB 
       'USE ?;
       SELECT DB_NAME();
     SELECT * FROM sys.procedures WHERE name = ''CleanSysDatabaseLog''' 

Open in new window

0
Éric MoreauSenior .Net ConsultantCommented:
you can also use the free SQL Search: http://www.red-gate.com/products/sql-development/sql-search/
0
Jim HornMicrosoft SQL Server Developer, Architect, and AuthorCommented:
>is there a quick way to check where does this stored procedure located ?
Just to state the obvious, it's not a good programming practice to tell SQL Server to 'go fish' for an object.
You'll want to explicitly state where it's at.
0
AXISHKAuthor Commented:
Tks
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SQL Server 2008

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.