存储过程如果存在则不给出正确答案
我创建了一个 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为您需要在某处添加
和 [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.