我正在尝试编写一个接受两个输入(内容ID和内容类型)的SQL查询,根据用户设置的内容类型从不同的源表填充临时表,然后最终针对temp运行查询表.我想我会把我的临时表合并到我的IF/ELSE语句中.
所以我的问题是,为什么这会返回一些非零数量的结果:
DECLARE @contentID int, @contenttype varchar
SET @contentid = 28861
SET @contenttype = 'resource'
DECLARE @tags_current TABLE (contentID int, taxonomyID int, isPrimary int)
INSERT INTO @tags_current (contentID, taxonomyID, isPrimary)
SELECT resourceID as contentID, taxonomyID, isPrimary
FROM resource2taxonomy r2t
WHERE r2t.resourceID = @contentID
SELECT * FROM @tags_current
Run Code Online (Sandbox Code Playgroud)
而这会返回零结果:
DECLARE @contentID int, @contenttype varchar
SET @contentid = 28861
SET @contenttype = 'resource'
DECLARE @tags_current TABLE (contentID int, taxonomyID int, isPrimary int)
IF (@contenttype = 'resource')
BEGIN
INSERT INTO @tags_current (contentID, taxonomyID, …Run Code Online (Sandbox Code Playgroud)