?
Solved

SQL Trigger selecting another database

Posted on 2016-09-27
4
Medium Priority
?
58 Views
Last Modified: 2016-09-27
I have a trigger to email me when a field changes in one table. I want it to use an email address from a table in another database, how do I do this?

Variables are these:  @Rep varchar(20),  @Sord varchar(20)

@Sord is taken from the table that is being changed in the current database.

This is the line that does not work: -
                  set @Rep = isnull((Select Salesperson from SERVER.dbName.dbo.Table
                  where SalesOrder = @Sord),'None')

It returns 'None' even though I know the data exists in the other database.

Can anyone help?
0
Comment
Question by:HKFuey
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 51

Accepted Solution

by:
Vitor Montalvão earned 2000 total points
ID: 41817421
Try to put the ISNULL inside:
Select @Rep = ISNULL(Salesperson,'None') 
from SERVER.dbName.dbo.Table
where SalesOrder = @Sord

Open in new window

0
 

Assisted Solution

by:HKFuey
HKFuey earned 0 total points
ID: 41817429
Hi Vitor,
Thaks for responding so quickly but I have solved it, the reason was the data was in different formats in the 2 databases, SalesOrder
Db1 123456
DB2 000000000123456
0
 
LVL 51

Expert Comment

by:Vitor Montalvão
ID: 41817433
Yeah, that was my next question to you but I'm happy that you solved it out.
Cheers
0
 

Author Closing Comment

by:HKFuey
ID: 41817436
Thanks for speedy response!!
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
Recently we ran in to an issue while running some SQL jobs where we were trying to process the cubes.  We got an error saying failure stating 'NT SERVICE\SQLSERVERAGENT does not have access to Analysis Services. So this is a way to automate that wit…
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.
Suggested Courses

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question