我试图通过特定的if条件获得额外的bool列 如何存档?这是我到目前为止所做的,但它无法正常工作
INSERT INTO @Result
SELECT o.ID,o.PRTableID,o.Message,o.StartTime,e.Name
FROM PROrder as o
LEFT JOIN PREmployee as e ON o.PREmployeeID = e.ID
CROSS JOIN (SELECT CASE WHEN @GroupId IS NULL THEN 0 ELSE 1 END )
答案 0 :(得分:3)
我假设你试图根据@GroupId值将0/1插入@Result表。如果是,请将Case Expression
添加到Select
列表。
INSERT INTO @Result
SELECT o.ID,o.PRTableID,o.Message,o.StartTime,e.Name,
CASE WHEN @GroupId IS NULL THEN 0 ELSE 1 END
FROM PROrder as o
LEFT JOIN PREmployee as e ON o.PREmployeeID = e.ID