Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Query from Two Databases within the same stored procedur
Message
From
10/09/2007 12:54:57
Cetin Basoz
Engineerica Inc.
Izmir, Turkey
 
General information
Forum:
Microsoft SQL Server
Category:
SQL syntax
Environment versions
SQL Server:
SQL Server 2000
Miscellaneous
Thread ID:
01253453
Message ID:
01253457
Views:
21
This message has been marked as the solution to the initial question of the thread.
>I'm trying to move our audit activity file into a separate database on the same server. Moving it wasn't hard, but it is a series of keys, with a text field for description of the event. The hard part now is trying to figure out how to query it and get the data out of the other database that the keys really relate to. For example below, I'm trying to get the back data from the audit and the user name of based off the user key that is in the audit. The example below does not work, but it seems like it should somehow be possible. I'm running the query from the Query Analyzer right now, and I get the error:
>
>
>Invalid object name 'ctoredev.users'.
>
>
>ctoredev is the master database for the application.
>ctoreaudit is the audit database
>
>
>select AuditID,actionDT,UserID, actiontype,
>	(select username from ctoredev.users where ctoredev.users.UserID=coAudit.UserID) as UserName
>from coAudit
>
>
>
>Thanks for any help. Maybe it's not possible and I'll just have to right the denormalized data into the audit, but I'm trying to avoid that.
>
>Kirk

Kirk,
You can specifiy the database a table belongs to:

from ctoredev..users

or with also qualifying the schema/owner:

from ctoredev.dbo.users

Cetin
Çetin Basöz

The way to Go
Flutter - For mobile, web and desktop.
World's most advanced open source relational database.
.Net for foxheads - Blog (main)
FoxSharp - Blog (mirror)
Welcome to FoxyClasses

LinqPad - C#,VB,F#,SQL,eSQL ... scratchpad
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform