'Use DB' option in Stored procedures

  • I have some of the commands in my SP like below but not able to use 'Use Database' option , any workaround?

    sp_helpfile

    sp_start_job

  • Hi,

    Just want to make sure that I got you question right.

    Do you mean you are getting some kind of error message when you are trying to execute sp_helpfile and sp_start_job. If yes, then can you please give the error message.

  • If I read your question right you are trying to do a USE statement in a sproc and it won't let you. MY guess is that you are doing a USE msdb so you can execute the start job.. You can reference the sproc in the database directly..

    EXEC databasename.dbo.sprocname

    or

    EXEC databasename..sprocname

    I recommend the first way, it performas faster, or at least MS says it does..

    CEWII

  • You can try like this...

    DECLARE @sql NVARCHAR(1000)

    DECLARE @DBNAME VARCHAR(40)

    SELECT @DBNAME = 'MSDB'

    SELECT @sql = 'EXEC'

    SELECT @sql = @sql + ' '+@DBNAME +'..sp_helpfile'

    EXEC SP_EXECUTESQL @sql

  • Guys you rock ,thnx

  • it looks like i am stuck with dbcc shrinkfile , any idea how i can use the database name in the stored procedure for dbcc shrinkfile with specific db?

  • DECLARE @varname varchar(255)

    SELECT @varname = 'DBCC SHRINKFILE( ' + @FileNameWeGotSomewhereElse + ' ) '

    EXEC ( @varname )

    Comes to mind..

    CEWII

Viewing 7 posts - 1 through 6 (of 6 total)

You must be logged in to reply to this topic. Login to reply