我有一个简单的选择,如何将select语句的计数分配给@count
DECLARE @count int
SELECT Tag FROM @Tags intersect SELECT Tag from @TagsFromRecord
set @count= (select count(1)
from (SELECT Tag
FROM @Tags
intersect
SELECT Tag
from @TagsFromRecord)) >> incorrect syntax
或
select @count= count(1) from (SELECT Tag
FROM @Tags
intersect
SELECT Tag
from @TagsFromRecord)
答案 0 :(得分:1)
你需要一个别名:
DECLARE @count int
set @count=
(
select count(1)
from
(
SELECT Tag FROM @Tags
intersect
SELECT Tag from @TagsFromRecord
) AS T
)
答案 1 :(得分:0)
我认为,这也可行,
DECLARE @count int
select @count = count(1)
from
(
SELECT Tag FROM @Tags
intersect
SELECT Tag from @TagsFromRecord
) AS T