请教个sql基础的问题
下面的存储过程,当使用isnull(id,0)查询id的时候,当数据不存在的时候返回的不是0,好像是个null
在红色部分我应该怎样判断
USE [YFTrade]
GO
/****** Object: StoredProcedure [dbo].[dispatch_receipt_Checked] Script Date: 03/11/2014 16:57:59 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author: <Author,,Name>
-- Create date: <Create Date,,>
-- Description: <Description,,>
-- =============================================
ALTER PROCEDURE [dbo].[dispatch_receipt_Checked]
-- Add the parameters for the stored procedure here
@Output int output,
@ID varchar(100) ,
@type varchar(100),
@driveLicense varchar(100) ,
@drivingLicense varchar(100),
@driveCode varchar(100),
@engineCode varchar(100),
@carSort varchar(100),
@carType varchar(100),
@tel varchar(100),
@operator varchar(100) ,
@operDate datetime,
@GMID varchar(100),
@identification varchar(100),
@name varchar(100),
@oper_ID varchar(100)
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
begin TRANSACTION
declare @rtn int
set @rtn = 0
-- Insert statements for procedure here
Begin
Insert into [dbo].[D-BFPC-Dispatch-His]
select *,@Operator,GETDATE(),1 from [dbo].[D-BFPC-Dispatch] where [ID] = @ID
end
If(@type <> '0')
Begin
Update [dbo].[D-BFPC-Dispatch]
Set [receiptChecked] =0
Where [ID]=@ID
if(@@error <> 0) or (@@ROWCOUNT <> 1)
begin
set @rtn = 2
goto Error
end
end
else
declare @CMID int
select @CMID=ISNULL(id,0)from [dbo].[D-JC-CarManagement] where GMID=@GMID and drivingLicense=@drivingLicense and name=@name
if(@CMID=0)
begin
insert into [dbo].[D-JC-CarManagement](
[driveLicense],
[drivingLicense],
[driveCode],
[engineCode],
[carSort],
[carType],
[tel],
[operator],
[oper_date],
[GMID],
[identification],
[name]
)
Values
(
@driveLicense,
@drivingLicense,
@driveCode,
@engineCode,
@carSort,
@carType,
@tel,
@operator,
@operDate,
@GMID,
@identification,
@name
)
select @CMID=ISNULL(id,0)from [dbo].[D-JC-CarManagement] where GMID=@GMID and drivingLicense=@drivingLicense and name=@name
Update [dbo].[D-BFPC-Dispatch]
Set [receiptChecked]=@CMID
Where [ID]=@ID
END
if(@@error <> 0) or (@@ROWCOUNT <> 1)
begin
set @rtn = 2
goto Error
end
COMMIT TRANSACTION
set @Output = @rtn
RETURN @rtn
Error:
ROLLBACK TRANSACTION
set @Output = @rtn
RETURN @rtn
END
-----