更新空单元格 - 此存储过程不起作用 - 为什么?
我正在做一个健身软件。我有一个登录注销系统。当会员登录时,此数据会放入表中,使注销列为空。然后,当会员注销时,注销单元格会更新。到这里就可以了。但如果会员登录和退出两次,我不希望更改第一次的退出时间。我只想更新空单元格或登录时间为最长的位置。我有以下存储过程,没有错误,但运行时注销单元没有发生任何事情!
ALTER proc [dbo].[updateSignOutMem]
@ID nvarchar(50), @signOut nvarchar(50),@date nvarchar(50)
as
update [DateTable]
set SignOut = @signOut
where ID = @ID AND [Date] = @date and SignOut = null ;
im doing a gym software. i have a signin signout system.when members sign in this data is put in a table leaving the signout colomn empty.then when member sign out the signout cell is updated.up to here is fine. but if the member signed in and out twice i dont want the sigout time of the first time to be changed.i want only the null cell to be updated or where the signin time is max. i have the following stored procedure with no errors but when running nothin is happening to the signout cell!
ALTER proc [dbo].[updateSignOutMem]
@ID nvarchar(50), @signOut nvarchar(50),@date nvarchar(50)
as
update [DateTable]
set SignOut = @signOut
where ID = @ID AND [Date] = @date and SignOut = null ;
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
解决方案:将
SignOut = null
替换为SignOut IS NULL
。原因:与 NULL 的比较始终返回 NULL,并且计算结果为 NULL 的 WHERE 子句将被视为 FALSE。例如,
SELECT * FROM myTable WHERE NULL = NULL
将返回零条记录而不是整个表。说明:
NULL
值是一个“未知”值,因此比较两个未知值的结果也是未知的。此三值逻辑(真、假、未知)的描述可以 在维基百科上找到。PS:SQL Server 提供更多的数据类型 不仅仅是 nvarchar(50)。使用它们! :-)
Solution: Replace
SignOut = null
withSignOut IS NULL
.Why: Comparisons with NULL always return NULL, and a WHERE clause that evaluates to NULL is treated as FALSE. For example
SELECT * FROM myTable WHERE NULL = NULL
will return zero records rather than the whole table.Explanation: A
NULL
value is an "unknown" value, so the result of comparing two unknown values is also unknown. A description of this three-valued logic (true, false, unknown) can be found on Wikipedia.PS: SQL Server provides much more data types than just nvarchar(50). Use them! :-)
尝试写作
Try writing