1

我创建了一个存储过程,它按状态、船名和到期日过滤许可证申请记录。该代码已运行用于过滤状态和船舶名称,但EXPIRY DATE.

该函数应使用 ajax 日历根据文本框上的输入过滤到期日期。

我认为我过滤有效期的条件有问题。

有什么建议么 ?

USE [PhilfishPhilcatch]
GO
/****** Object:  StoredProcedure [dbo].[rectesting]    Script Date: 11/07/2013 08:53:48 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

ALTER PROCEDURE [dbo].[rectesting]


@VesselName Varchar (30) = NULL,
@Status Varchar (10) = NULL,
@DateReleased date = NULL,
@ExpiryDate date = NULL,
@DateIssued date = NULL,
@Cfvgl_Upload varchar = NULL


AS
    BEGIN
        IF (@Status = 1)
            begin
            SELECT a.v_id, a.ship_name, b.status, b.cfvgl_validity_start , b.cfvgl_validity_end, b.cfvgl_path, b.cfvgl_date_released 
            FROM vessel_details as a INNER JOIN
            cfvgl as b ON a.v_id = b.v_id 
            WHERE
            a.ship_name LIKE ISNULL(@VesselName+'%', a.ship_name) AND
            (b.status = 4 OR b.status = 7)  
            end 

        IF (@Status <> NULL OR @Status <> '')
        begin
            SELECT a.v_id, a.ship_name, b.status, b.cfvgl_validity_start , b.cfvgl_validity_end, b.cfvgl_path, b.cfvgl_date_released 
            FROM vessel_details as a INNER JOIN
            cfvgl as b ON a.v_id = b.v_id 
            WHERE
            a.ship_name LIKE ISNULL(@VesselName+'%', a.ship_name) AND
            b.status = @Status  
            end

        IF (@ExpiryDate <> NULL OR @ExpiryDate <> '')
        begin   
            SELECT a.v_id, a.ship_name, b.status, b.cfvgl_validity_start , b.cfvgl_validity_end, b.cfvgl_path, b.cfvgl_date_released 
            FROM vessel_details as a INNER JOIN
            cfvgl as b ON a.v_id = b.v_id 
            WHERE
            b.cfvgl_validity_end = ISNULL (@ExpiryDate, b.cfvgl_validity_end)
        end
    END 
4

4 回答 4

2
@Status <> NULL 

应该

@Status IS NOT NULL 
于 2013-11-07T09:01:26.540 回答
0

Null 值不能与 (= > <) 运算符进行比较。在这种情况下使用“IS”运算符

于 2013-11-07T09:12:00.777 回答
0

如果要检查一个值是否为 NULL,则不能显式地与 NULL 进行比较。您需要将语句编写为:

IF (@EXPIRY_DATE IS NOT NULL OR ...)
于 2013-11-07T09:03:55.907 回答
0

建议:

IF ( NULLIF( @ExpiryDate, '' ) IS NOT NULL )
...
于 2013-11-07T09:07:11.313 回答