2010-10-15 104 views
1

我創建了一個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 

回答

2

我認爲你需要在某處添加一個and [CRID] = @myECR。現在你只是檢查是否有任何記錄已經超級贊成

+0

哎呀 - 是的 - 我的壞!你確定無誤。謝謝回覆! – randy 2010-10-15 16:58:03

+0

@randy歡迎您。如果我的回答對您有幫助,請點擊左邊的複選標記以接受答案。 – 2010-10-15 16:59:06