I'm not quite sure on the correct way to see if a row exists in both databases. Please help.
@pStoreNum bigint,
@pGuid varchar(100)
IF EXISTS (SELECT Guid FROM dbo.StoreSales WHERE Guid = @pGuid
AND SELECT Guid F开发者_JAVA技巧ROM dbo.StoreReporting WHERE Guid = @pGuid)
BEGIN
UPDATE
dbo.StoreReporting
SET
ValidCount = ValidCount + 1
WHERE
StoreNum = @pStoreNum
END
You just need to specify EXISTS twice:
IF EXISTS (first select) AND EXISTS (second select)
BEGIN
...
END
IF EXISTS (SELECT Guid FROM dbo.StoreSales ss
INNER JOIN dbo.StoreReporting sr
ON sr.Guid = ss.Guid
WHERE ss.Guid = @pGuid)
This will check that it's in both tables. The INNER JOIN
will limit the result set to rows that have the same GUID
in both tables, so if it exists in that JOIN
ed result set it exists both places.
精彩评论