在比较两个查询时,我有一大组数字用作变量。这些查询运行相当耗时,所以我希望能够自动执行此操作来整理两个查询返回的具有不同行的所有变量。我对任何建议持开放态度。
用于@key的号码在另一台服务器上。我有第三个查询来返回这些数字。
我将在下面发布两个查询。
DECLARE @SubscriberID bigint
DECLARE @key int
set @key = 128604576
SELECT TOP(1) @SubscriberID = M.WarehouseID
FROM vwCache_Full V (NOLOCK)
LEFT JOIN Latest m (NOLOCK)
ON m.WarehouseID = v.PersonKey
WHERE V.memberid = @key
ORDER BY
V.tapeid DESC, V.linekeyid DESC
SELECT TOP 1
AddrLn1, AddrLn2
FROM Latest
WHERE
WarehouseID = @SubscriberID
ORDER BY
TapeID DESC, LineKeyID DESC
- 下一个查询
SELECT TOP 1 m.AddrLn1, m.AddrLn2
FROM Latest m (NOLOCK)
INNER JOIN Latest p ON m.WarehouseID = p.WarehouseID
WHERE m.SSN = @key
ORDER BY m.TapeID Desc
在这里找到另一个答案,帮助...使用......
DECLARE @RowsToProcess int
DECLARE @CurrentRow int
DECLARE @SelectCol1 int
DECLARE @table1 TABLE (RowID int not null primary key identity(1,1), col1 int )
INSERT into @table1 (col1) SELECT col1 FROM table2
SET @RowsToProcess=@@ROWCOUNT
SET @CurrentRow=0
WHILE @CurrentRow<@RowsToProcess
BEGIN
SET @CurrentRow=@CurrentRow+1
SELECT
@SelectCol1=col1
FROM @table1
WHERE RowID=@CurrentRow
--do your thing here--
END