[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

SQL Trigger selecting another database

Posted on 2016-09-27
4
Medium Priority
?
70 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 53

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 53

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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

When trying to connect from SSMS v17.x to a SQL Server Integration Services 2016 instance or previous version, you get the error “Connecting to the Integration Services service on the computer failed with the following error: 'The specified service …
Microsoft Access has a limit of 255 columns in a single table; SQL Server allows tables with over 255 columns, but reading that data is not necessarily simple.  The final solution for this task involved creating a custom text parser and then reading…
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.
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.
Suggested Courses

834 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