Solved

SQL Trigger selecting another database

Posted on 2016-09-27
4
30 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 45

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 45

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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Suggested Solutions

This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.

705 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now