[x]
Posted via EE Mobile

Search, ask, and monitor your questions on the go with EE Mobile. Visit Experts Exchange from your mobile device and never be out of touch again.

Question
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

7.2

How to run stored procedures in database A while logged into database B?

Asked by dqmq in SQL Server 2005, MS SQL Server

HI,
I need some help setting up an SQL Server environment. I have a database that is chock full of my favorite utility procedures and functions that I use all the time at different client sites.  As it stands, in order to run those utilities, I install them in the client database and all is fine.  However, that creates some administrative/logistic headaches for me:
  --I install the procs/functions is with a CREATE PROC script, which means I need to maintain that every time I add a new procedure or one of them changes.
  --some clients understandably resist the intrusion of my scripts into their databases.  Frankly, I think it's an obnoxious practice myself.
  --purging the objects when I leave is a hassle

It would be much easier if I could just attach my database to the client's server and run the scripts from there:  1. Simple installation/de-installation  2. No introduction of my objects into the client database.

But, I can't get it work.  Suppose my utilities are in database U, which is attached to the client's server S with client database C.  I want to run my utilities in database U against the tables in database C.   I want to do this without explicitly naming database C in my utilities, since I want them to be portable.  

To simplify by example, see the code snippet.

When that runs, I want it to see the tables from C, but it shows the tables from U, instead.  In other words, my database context is the database where the proc is stored, not the one I am connected to or running against.

Specifically, my questions are:
1.  Is there something simple that I am overlooking?  Can I get my example to show the results from the context of the database C (without hardcoding the database name)?

2.  Is there a better way to accompish my goal of a easily porting a package of utilities? What's the best practice?





 

 


 



1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
use u
go
create proc dbo.ShowTables as select name from sys.tables
go
create table dbo.Utable (i int)
go
 
use c
go
create table dbo.Ctable (i int)
go
 
exec u.dbo.showtables
go
 
 
Name
-----------------------------------------
UTable
[+][-]06/10/08 11:20 AM, ID: 21753610Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]06/10/08 11:49 AM, ID: 21753875Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]06/11/08 04:05 PM, ID: 21764861Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]06/12/08 08:14 AM, ID: 21770392Accepted Solution

View this solution now by starting your 30-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

About this solution

Zones: SQL Server 2005, MS SQL Server
Sign Up Now!
Solution Provided By: ScottPletcher
Participating Experts: 2
Solution Grade: B
 
[+][-]06/13/08 09:05 PM, ID: 21784031Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]08/28/08 09:04 AM, ID: 22336506Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
 
Loading Advertisement...
20091111-EE-VQP-89 / EE_QW_2_20070628