gpt4 book ai didi

SQL 存储过程用 IF-ELSE 修改

转载 作者:行者123 更新时间:2023-12-02 07:23:41 24 4
gpt4 key购买 nike

到目前为止,这是我的存储过程

ALTER PROC [dbo].[getItems]
(
@EventId int,
@OrgUserId int
) AS

BEGIN

DECLARE @BoardBookId int;
SET @BoardBookId = (SELECT bb.BoardbookId FROM Boardbook bb WHERE bb.ItemId = @EventId);

WITH PermissionDeniedAttachments AS
(
SELECT bbi.CategoryItemId
FROM BoardbookItem bbi
INNER JOIN CategoryItem ci ON ci.CategoryItemId = bbi.CategoryItemId
WHERE bbi.BoardbookId = @BoardBookId AND bbi.CategoryItemId > 0 AND ci.catID NOT IN (SELECT catID from dbo.f_Categories(@OrgUserId))
)
SELECT
bbi.BoardbookId,
bbi.BoardbookItemId,
bbi.CategoryItemId,
bbi.ChBy,
bbi.ChDt,
bbi.CrBy,
bbi.CrDt,
bbi.DeletedBy,
bbi.DeletedDt,
bbi.Description,
bbi.Duration,
bbi.ParentBoardbookItemId,
bbi.SortOrder,
bbi.Title,
bbi.Resolutions,
bbi.Presenter,
bbi.BoardbookItemType,
u1.Name_FirstLast as [ItemCreatedByName],
u2.Name_FirstLast as [ItemChangedByName],
CAST(CASE WHEN ci.deletedDt IS NULL THEN 0
ELSE 1 END AS BIT) AS Deleted,
i.itemType as [DocType],
ISNULL(ci.catID, 0) AS CatId,
ISNULL(ci.itemID, 0) AS ItemId,
d.docID as docId,
d.docPages as DocPages,
d.docPwdProtected AS HasPassword,
bbi.BoardbookItemTypeCustom
from BoardbookItem bbi
LEFT JOIN Users u1 on u1.UserName=bbi.CrBy
LEFT JOIN Users u2 on u2.UserName=bbi.ChBy
LEFT OUTER JOIN CategoryItem ci ON bbi.CategoryItemId IS NOT NULL AND bbi.CategoryItemId = ci.CategoryItemId
LEFT JOIN Item i ON ci.itemID = i.itemID
LEFT JOIN Documents d on d.docID = bbi.DocId
where bbi.BoardbookId=@BoardBookId AND bbi.DeletedDt IS NULL AND
(bbi.CategoryItemId IS NULL OR bbi.CategoryItemId NOT IN (Select CategoryItemId from PermissionDeniedAttachments))

现在我想要的是放置一个var @submenuitem bit 并测试它...所以,如果 @submenuitem = 0 作为响应,我将得到与现在相同的效果,但是如果 @submenuitem = 1 我想再检查一次“where” for ex。'AND bbi.ParentBoardbookItemId='0'

似乎可以使用 IF ELSE 语句来完成,但不幸的是我无法以正确的方式完成

提前致谢!

最佳答案

没有 if...else 语句绝对是可能的。

只需将此添加到where 条件

AND ((bbi.ParentBoardbookItemId='0' and @submenuitem = 1) or @submenuitem = 0)

它会像您描述的那样工作。

关于SQL 存储过程用 IF-ELSE 修改,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36870210/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com