Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

dynamic sql

Status
Not open for further replies.

vlitim76

Programmer
Jun 1, 2006
19
GB

I have a situation in a stored procedure where I need to call another procedure that could be in different databases. The @extDatabase is being passed from the application and I am currently doing the below. question is can I do this dynamically and not have to do an if statement for each database.

Code:
if @extDatabase = 'TEST'
     execute @ErrorCode = TEST.dbo.sp_PLay @date 
else if @extDatabase = 'LIVE'
     execute @ErrorCode = LIVE.dbo.sp_PLay @date

Thanks

tim
 
something like this?

Code:
declare @sqlStr varchar(500)
set @sqlStr = @extDatabase + '.dbo.sp_PLay ' + @date
exec (@sqlStr)

Hope it helps,

ALex

Ignorance of certain subjects is a great part of wisdom
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top