I’m using parts of a replication script written by a well known blogger. I want to make the part I listed below add 1 more column from a totally different table that only holds 1 row. Basically that table with a single row has a site name on it, and I want that site name from that table to populate as part of this INSERT INTO.
I know SQL 2005 introduced OUTER APPLY, but I am not sure if that is the best method to go with. Any sugegstions are welcome. Thanks.
Insert Into dbo.dba_replicationMonitor
(
monitorDate
, publicationName
, publicationDB
, iteration
, tracer_id
, distributor_latency
, subscriber
, subscriber_db
, subscriber_latency
, overall_latency
, SiteNameFromSiteInfoTable --Need to add this
)
Select
@currentDateTime
, @publicationToTest
, @publicationDB
, iteration
, tracer_id
, IsNull(distributor_latency, 0)
, subscriber
, subscriber_db
, IsNull(subscriber_latency, 0)
, IsNull(overall_latency,
IsNull(distributor_latency, 0) + IsNull(subscriber_latency, 0
)
, sitename = 'SELECT sitename FROM tblSiteInfo' --need this query to insert as well
)
From @tokenResults;
I was thinking of a variable but I don’t thnk passing the variable will be enough. Any help is greatly appreciated. Thanks.
You can just join to the second table as normal. If there’s only one row in this other table (and will only ever be one row), it’s not going to double your results. So, like this: