检查存储过程中的参数是否为空或空 [英] Check if a parameter is null or empty in a stored procedure

查看:34
本文介绍了检查存储过程中的参数是否为空或空的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道如何检查一个参数是否为空,但我不知道如何检查它是否为空......我有这些参数,我想检查前面的参数是空还是空,然后像下面这样设置它们

I know how to check if a parameter is null but i am not sure how to check if its empty ... I have these parameters and I want to check the previous parameters are empty or null and then set them like below

ALTER PROCEDURE [dbo].[GetSummary]
    @PreviousStartDate NVARCHAR(50) ,
    @PreviousEndDate NVARCHAR(50) ,
    @CurrentStartDate NVARCHAR(50) ,
    @CurrentEndDate NVARCHAR(50)
AS
  BEGIN
    IF(@PreviousStartDate IS NULL OR EMPTY)
        SET @PreviousStartdate = '01/01/2010'  for example..

非常感谢您的帮助.

推荐答案

我有时使用 NULLIF 像这样...

I sometimes use NULLIF like so...

IF NULLIF(@PreviousStartDate, '') IS NULL

可能没有理由比@Oded 和@bluefeet 建议的方式更好,只是风格偏好.

There's probably no reason it's better than the way suggested by @Oded and @bluefeet, just stylistic preference.

@danihp 的方法真的很酷,但是当我认为是 null 或为空时,我疲惫的老大脑不会去 COALESCE :-)

@danihp's method is really cool but my tired old brain wouldn't go to COALESCE when I'm thinking is null or empty :-)

这篇关于检查存储过程中的参数是否为空或空的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆