基于输入的 SQL Server 日期检查
这个问题已经困扰了我很多次,我现在决定尝试找到正确的解决方案,而不是我总是恢复到(复制sql语句)的冗长/肮脏/可怕的方式
该表有一个日期列默认值为 NULL
现在我需要做的是将值 (-1,0,1) 传递给一个 sql 语句,该语句确定要撤回的内容
-1 - should bring back all rows
0 - should bring back rows with a NULL date value
1 - should bring back rows with a valid date value
我尝试使用 CASE 语句,但逻辑运算符需要根据情况进行更改关于传递给查询的值。
让我们只调用表 Quotes 并完成列,所以...
CREATE TABLE 'Quotes'
(
completed DATETIME default(NULL)
)
解决方案需要适用于 SQL Server 2000,并且我正在使用存储过程而不是动态 SQL。 所以它真的需要在一份声明中全部体现。
谢谢 担
This problem has bugged me so many times and i have now decided to try and find the proper solution for it, instead of my long-winded/dirty/horrible way I always revert to (copying the sql statement)
The table has a date column with a default value of NULL
Now what i need to do is pass a value (-1,0,1) to an sql statement which determines what to pull back
-1 - should bring back all rows
0 - should bring back rows with a NULL date value
1 - should bring back rows with a valid date value
I have tried using CASE statements, but the logical operator would need to change depending on the value being passed to the query.
Lets just call the table Quotes and the column completed, so...
CREATE TABLE 'Quotes'
(
completed DATETIME default(NULL)
)
Solution needs to be for SQL Server 2000, and i'm working in stored procedures not dynamic SQL. So it really needs to be all in one statement.
Thanks
Dan
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
WHERE 子句中类似这样的内容
Something like this in the WHERE clause
试试这个:
拉杰
Try this:
Raj