Quantcast
Channel: Forum Getting started with SQL Server
Viewing all articles
Browse latest Browse all 4729

UDP to query the current DB

$
0
0

Hi, 

I'm refactoring my SQL into UDP. The problem is that I want to define the UDP in another DB, because it is a common task that can apply to a bunch of my DBs. 

The SQL works fine before refactoring into UDP in another DB, but having done that, I got the "Invalid object name " error.

I think it is because that previously the "select mycol from mytab" works  under current DB. Having moved to mycommondb, and calling it via

Exec mycommondb..commontask 

would fail, even if still under the current DB. 

Any way to fix it so that my commontask would work with whatever my current DB is? 

*UPDATE*: 

The mycommondb..commontask is called within the context of current DB, and it contains a single "select mycol from mytab..." SQL statement. That single "select mycol from mytab..." SQL statement works fine within the context of current DB, shouldn't it work the same when refactored into UDP? 

OK, for whatever reason it doesn't work the same, is there any way in UDP to sense what's the calling context is, i.e., the current DB when calling it, and I'll prelude my SQL with a "USE ... GO"? Is it possible?

Thanks







Viewing all articles
Browse latest Browse all 4729

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>