我正在尝试执行以下查询,但它会通过聚合或其他Null
操作消除警告SET
值。
select
s.CurrentDate,
s.game_id,
s.Searchstring,
sm.type_of_game,
case when(count(t.game_id)>0) then 'Y' else 'N' end as scorestatus,
case when(count(i.game_id)>0) then 'Y' else 'N' end as scorestatusindividual,
sm.image_path,g.datetime,'' as score_keeper
from dbo.Search s with(nolock)
left outer join dbo.TeamGameResult t with(nolock) on s.game_id = t.game_id
left outer join dbo.IndividualGameResult i with(nolock) on i.game_id = s.game_id
join dbo.Game g with(nolock) on g.game_id=s.game_id
join dbo.AdditionalDetails ad on ad.AdditionalDetails_id = g.AdditionalDetails_id
join dbo.SportMaster sm with(nolock) on sm.SportsMaster_id = ad.SportsMaster_id
where (( Searchstring+' '+ convert(nvarchar(500),s.CurrentDate,101) Like '%01/15/2013%'
and Searchstring+' '+ convert(nvarchar(500),s.CurrentDate,101) Like '%Soccer%'))
and convert(varchar(10),g.datetime,101) in ('01/15/2013','01/14/2013')
group by s.game_id,
s.Searchstring,
sm.type_of_game,
s.CurrentDate,
sm.image_path,
g.datetime
order by g.datetime desc
答案 0 :(得分:1)
它只是警告你,因为你正在使用
... when(count(i.game_id)>0) then 'Y' else 'N' end ...
Count是一个聚合函数,不能计算game_id为null的值。您可以使用ISNULL函数(http://msdn.microsoft.com/en-GB/library/ms184325.aspx),例如:
count(ISNULL(i.game_id, 0))
但是它也会计算所有的NULL值。因此,如果您不想要它,则需要在WHERE部分添加额外的检查