Solved

SQL Trigger selecting another database

Posted on 2016-09-27
4
37 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
  • 2
  • 2
4 Comments
 
LVL 47

Accepted Solution

by:
Vitor Montalvão earned 500 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 47

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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

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.
For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…

809 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