我在2个类似的SQL Select Querys'上有错误,我的假设是我错误地使用了NULL。有人看了看,告诉我哪里出错了。
string CountHolidayQuery = "SELECT StartDate, EndDate FROM [Holiday] WHERE PayrollNo = @PayrollNo AND Authorised IS NOT Null";
和
string CountRequestedQuery = "SELECT StartDate, EndDate FROM [Holiday] WHERE PayrollNo = @PayrollNo AND Authorised IS Null";
答案 0 :(得分:4)
Authorised = Null
无效,应为Authorised IS Null
或Authorised IS NOT Null
答案 1 :(得分:4)
在SQL中,Null并不像值那样对待,实际上是一种特殊情况,其语法为Is Null
和Is Not Null
,例如
string CountHolidayQuery = "SELECT StartDate, EndDate FROM [Holiday] WHERE PayrollNo = @PayrollNo AND Autorised Is Not Null";
以及
string CountRequestedQuery = "SELECT StartDate, EndDate FROM [Holiday] WHERE PayrollNo = @PayrollNo AND Authorised Is Null";
在第一个声明中,Authorised
不应该为空,它输入错误,而是读取Autorised
答案 2 :(得分:2)
应该是" IS NOT
null",缺少查询IS
SELECT StartDate, EndDate FROM [Holiday] WHERE PayrollNo = @PayrollNo AND Autorised IS NOT Null";
第二个查询Authorised = Null
不是有效的sql
语法。
答案 3 :(得分:1)
我认为您错过了关键字
所以声明如下:
string CountHolidayQuery = "SELECT StartDate, EndDate FROM [Holiday] WHERE PayrollNo = @PayrollNo AND Autorised is NOT Null";