Solved

SQL Trigger selecting another database

Posted on 2016-09-27
4
42 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 49

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 49

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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
unable to reinstall SCVMM 2012 R2 - SQL errors. 5 42
Need help with another query 10 38
SP result not being displayed 5 44
SQL - Ordering Supervisor Hierarchy 2 13
JSON is being used more and more, besides XML, and you surely wanted to parse the data out into SQL instead of doing it in some Javascript. The below function in SQL Server can do the job for you, returning a quick table with the parsed data.
Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.
Viewers will learn how the fundamental information of how to create a table.

733 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