April 26, 2011 at 11:00 am
Hi, i am trying to write a merge query for the insert to the table. but the source table does multiple joins. not sure how do i write the merge query. any ideas??
below is the code that i want to turn into a merge query:
INSERT INTO Location
(
Id,
Number,
Climate,
Seismic,
Wind,
[Description],
IsMetric,
Created_By,
Created_Date,
ValuationId,
Modified_By,
Modified_Date,
Longitude,
Latitude,
ModuleFlags,
TaxRate
)
SELECT
hl.MasterId,
hl.Number,
hl.Climate,
hl.Seismic,
hl.Wind,
hl.[Description],
hl.IsMetric,
hl.Created_By,
hl.Created_Date,
@ValuationId,
hl.Modified_By,
hl.Modified_Date,
hl.Longitude,
hl.Latitude,
hl.ModuleFlags,
hl.TaxRate
FROM HistoricalLocation hl
JOIN HistoricalValuation hv ON hv.Id = hl.Id
JOIN Valuation v ON v.Id = hv.MasterId
WHERE v.Id = @ValuationId AND hl.Version = @Version AND hl.Sequence = 0
April 26, 2011 at 11:14 am
Please don't cross post. It just wastes peoples time and fragments replies.
No replies to this thread please. Direct replies to: http://www.sqlservercentral.com/Forums/Topic1098821-392-1.aspx
Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability
Viewing 2 posts - 1 through 1 (of 1 total)
You must be logged in to reply to this topic. Login to reply