我是T-SQL的新手,所以请耐心听我说。
我正在尝试遵循以下说明:
执行以下操作
Join Indivs16000 to Cmtes16 on Indivs16000.CmteID = Cmtes16.CmteID
with Indivs16000.RecipCode not like P* 如果您希望将个人贡献包括在领导力PAC中,请不要排除基于Recipcode。相反,应限制为Indivs.Party不为空且Indivs.Party<>“”(不等于空)。
我想把个人的贡献包括在领导力PACS中。为了遵循这些说明,我编写了以下查询:
JOIN Indivs16000 to Cmtes16
ON Indivs16000.CmteID = Cmtes16.CmteID
WITH Indivs16000.Party NOT NULL
AND Indivs16000.Party<>在执行时,我遇到了以下错误:
Msg 156, Level 15, State 1, Line 5
Incorrect syntax near the keyword 'Join'.
Msg 319, Level 15, State 1, Line 7
Incorrect syntax near the keyword 'with'. If this statement is a common table expression, an xmlnamespaces clause or a change tracking context clause, the previous statement must be terminated with a semicolon.哪里出了问题?我正在使用Microsoft SQL Server 2016 (Management Studio)。
发布于 2017-03-11 03:05:29
正如肖恩·兰格指出的那样,i.Party<>''或i.Party > ''消除了检查i.Party是否是null的需要。
您可以在select中选择要返回哪些列,以及这些列应该来自哪个表。
对表名使用别名使其更具可读性,并使您不必浪费一些finite number of keystrokes。
select
i.*
, c.col1
, c.col2
from Indivs16000 as i
inner join Cmtes16 as c
on i.CmteID = c.CmteID
where i.Party<>''
--and i.Party is not null /* not needed with i.Party <>'' */发布于 2017-03-11 03:05:21
SELECT *
FROM
Indivs16000 as A
INNER JOIN
Cmtes16 as B
ON A.CmteID = B.CmteID
WHERE AND A.Party != '' and A.Party is not nullhttps://stackoverflow.com/questions/42725884
复制相似问题