在传递带有null的参数时选择所有数据

时间:2018-08-02 13:50:09

标签: sql-server stored-procedures

我正在使用SQL Server2012。这是我的存储过程代码:

def writeToSFTP(df: DataFrame, path: String) = {
        df.write
          .format("com.springml.spark.sftp")
          .option("host", "hostname.test.fr")
          .option("username", "test_hostname")
          .option("password", "toto")
          .option("fileType", "csv")
          **.option("hdfsTempLocation","/user/currentuser/")**
          .option("delimiter", ",")
          .save(path)
      }

当我尝试使用以下命令执行

select * 
from tbl_Events te
where te.MainEventID = ISNULL(@EventID, te.MainEventID)
  and te.EventCityID = ISNULL(@CityID, te.EventCityID)
  and te.OwnerPassNo = ISNULL(@PassNo, te.OwnerPassNo)
  and te.[Owner] LIKE '%' + @Owner + '%'
  and te.isActive = 'true'

它返回0行,尽管我的表中有一些数据。

我在做什么错了?

1 个答案:

答案 0 :(得分:0)

请尝试:

select * from tbl_Events te
    where 
    (@EventID IS NULL OR te.MainEventID = @EventID) AND
    (@CityID IS NULL OR te.EventCityID = @CityID) AND
    (@PassNo IS NULL OR te.OwnerPassNo = @PassNo) AND
    te.[Owner] like '%' + @Owner + '%' AND
    te.isActive = 'true'

然后检查'isActive'是否期望'true'或1