I want to have a stored procedure that will take one SerialNumber nvarchar as it's input and check several databases to see if that serial number exists and if it does exist then return the result of the query, otherwise move onto the next database and do the same thing until all databases have been checked.
Current pseudocode:
IF(exists(select top 1 * from Server1.Database1.Table where num = @SerialNumberInput))
BEGIN
select top 1 * from Server1.Database1.Table where num = @SerialNumberInput
END ELSE
IF(exists(select top 1 * from Server2.Database2.Table where num = @SerialNumberInput))
BEGIN
select top 1 * from Server2.Database2.Table where num = @SerialNumberInput
END ELSE
--Server3.Database3
--Server4.Database4
--etc...
But I don't like all this query repetition and I don't like how I'm having to make a call to the server twice by calling the same query twice. I could save the result to a table variable and just check that but that feels hacky.