存储过程如果存在则不给出正确答案

发布于 2024-09-28 03:49:05 字数 875 浏览 2 评论 0原文

我创建了一个 sql 2005 存储过程来告诉我我正在搜索的 CRID 是否得到了主管的批准。 [SuperApproved] 是一个位,[CRID] 是 char(36)。即使 CRID 不存在,我仍然得到 1。 写这个有什么帮助吗?

USE [cr_Saturn2]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:  Randy Baker
-- Create date: 10/12/2010
-- Description: Check for Approved CRID in CostReportTracking
-- =============================================
alter PROCEDURE [dbo].[st_Is_CostReportApproved]
 -- Add the parameters for the stored procedure here
 @myECR char(36) = null  
AS
BEGIN
 -- SET NOCOUNT ON added to prevent extra result sets from
 -- interfering with SELECT statements.
 SET NOCOUNT ON;

if exists(
 select [CRID]
 from [dbo].[CostReportTracking]
 where [SuperApproved] = 1)

 -- exists- cost report is Approved by Supervisor
 select 1
else
 -- does not exist
 select 0    
END

I created a sql 2005 stored proc to tell me if the CRID I am searching for is approved by the supervisor. [SuperApproved] is a bit, [CRID] is char(36). Even if the CRID doesn't exist, I am still getting 1.
Any help in writing this?

USE [cr_Saturn2]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:  Randy Baker
-- Create date: 10/12/2010
-- Description: Check for Approved CRID in CostReportTracking
-- =============================================
alter PROCEDURE [dbo].[st_Is_CostReportApproved]
 -- Add the parameters for the stored procedure here
 @myECR char(36) = null  
AS
BEGIN
 -- SET NOCOUNT ON added to prevent extra result sets from
 -- interfering with SELECT statements.
 SET NOCOUNT ON;

if exists(
 select [CRID]
 from [dbo].[CostReportTracking]
 where [SuperApproved] = 1)

 -- exists- cost report is Approved by Supervisor
 select 1
else
 -- does not exist
 select 0    
END

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

零度℉ 2024-10-05 03:49:05

我认为您需要在某处添加 和 [CRID] = @myECR 。现在您只需检查是否有任何记录已超级批准

I think you need to add an and [CRID] = @myECR somewhere. Right now you are just checking if there is any record that has been SuperApproved.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文