[英]Adding a Where Clause on The Join statement
我曾嘗試在連接語句中的ON處添加一個where子句,但是我收到語法錯誤,我不確定將其放在哪里,因為我需要它從名為systemlookup的表中提取數據
DECLARE @OptionalModules TABLE (moduleid INT, name VarChar(200))
INSERT INTO @OptionalModules
SELECT CAST (LookupReference AS INT)
FROM dbo.systemlookup
left join @xml.nodes('//Modules/*') as organisation(license) on
organisation.license.value('local-name(.)', 'varchar(50)') =
case LookupReference
when '1' then 'a'
when '2' then 'b'
when '6' then 'c'
when '8' then 'd'
when '9' then 'e'
when '10' then 'f'
when '11' then 'g'
when '12' then 'h'
when '13' then 'i'
when '14' then 'j'
when '15' then 'k'
when '16' then 'l'
when '17' then 'm'
when '18' then 'n'
when '20' then 'o'
when '21' then 'p'
when '22' then 'q'
when '23' then 'r'
when '24' then 's'
when '25' then 't'
when '26' then 'u'
when '27' then 'v'
when '28' then 'w'
when '29' then 'x'
when '31' then 'y'
when '32' then 'z'
when '33' then 'aa'
when '16016' then 'bb'
end
在ON子句后添加一個AND,語法如下:
SELECT A
FROM Table A
INNER JOIN Table B ON A.ID = B.ID AND A.ID2 = B.ID2
感謝已經給出的答案,但是我找到了正確的方法,我也從代碼底部丟失了另一條SQL
DECLARE @OptionalModules TABLE (moduleid INT, name VarChar(200))
INSERT INTO @OptionalModules
SELECT CAST (LookupReference AS INT)
FROM dbo.systemlookup
left join @xml.nodes('//Modules/*') as organisation(license) on
organisation.license.value('local-name(.)', 'varchar(50)') =
case LookupReference
when '1' then 'a'
when '2' then 'b'
when '6' then 'c'
when '8' then 'd'
when '9' then 'e'
when '10' then 'f'
when '11' then 'g'
when '12' then 'h'
when '13' then 'i'
when '14' then 'j'
when '15' then 'k'
when '16' then 'l'
when '17' then 'm'
when '18' then 'n'
when '20' then 'o'
when '21' then 'p'
when '22' then 'q'
when '23' then 'r'
when '24' then 's'
when '25' then 't'
when '26' then 'u'
when '27' then 'v'
when '28' then 'w'
when '29' then 'x'
when '31' then 'y'
when '32' then 'z'
when '33' then 'aa'
when '16016' then 'bb'
end
where s.LookupTypeId = 1 and cast(case license.value('.', 'varchar(3)') when 'Yes' then 1 when 'No' then 0 else 1 end as bit) = 1
我將演員表之前的位置放在底部,現在返回30行而不是原來的2340行。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.