如果第一级不匹配,如何编写只执行二级查找的SQL语句。例如:
在下面的查询中,如果我的SEDOLCode
条件未返回记录,请继续使用RICCode查找条件2。
select
*, GETDATE()
from
Securities sec
where
sec.SEDOLCode = 'ABCDEF'
or sec.RICCode = '002815.SZ'
此查询返回两个不同的记录 - 例如:
1234 ABCDEF DUMY906.X
5675 EFTFS 002815.SZ
我正在从文件中获取数据以更新Price
表,如下所示。我想使用SedolCode
作为主查找。
IF @@ROWCOUNT = 0
INSERT INTO dbo.Price (sec.SecurityID, ClosingPrice, UpdatedDate, UpdatedByUser, Priced)
SELECT
..., GETDATE()
FROM
Securities sec
WHERE
sec.SEDOLCode = @SedolCode
OR sec.RICCode = @RicCode
答案 0 :(得分:0)
INSERT INTO dbo.Price
(
sec.SecurityID
, ClosingPrice
, UpdatedDate
, UpdatedByUser
, Priced
)
SELECT TOP 1 [specifiy fields to insert]
FROM
(
select 1 as myOrdering ...
, GETDATE()
from Securities sec
WHERE
(sec.RICCode = @RicCode AND sec.SEDOLCode != @SedolCode)
UNION
select 2 as myOrdering ...
, GETDATE()
from Securities sec
WHERE
(sec.RICCode = @RicCode AND sec.SEDOLCode != @SedolCode)
)SUB_Q ORDER BY myOrdering
答案 1 :(得分:0)
尝试这个逻辑基本上如果找到了sedolcode,那么它只会满足第一个条件。否则,该sedolcolde的计数将为0,它将查看riccode。
semop