SQL Server 2000 中的时间戳
我有一个名为 Table1
的表,其中包含 ID
和 TimeStamp
。
表结构
ID TimeStamp
1 0x0000000000047509
但是当我比较这些字段的组合时,它总是显示错误。这是什么原因呢?
我的查询是:
DECLARE @ID int
DECLARE @TimeStamp timestamp
SET @ID = 1
SET @TimeStamp = 0x0000000000047509
If EXISTS(SELECT 1 FROM Table1 WHERE ID = @ID AND TimeStamP = @TimeStamp)
BEGIN
SELECT 1 AS RetVal
END
ELSE
BEGIN
SELECT -1 AS RetVal
END
我的存储过程如下
CREATE PROCEDURE [dbo].[Check] (
@XMLDoc ntext
)AS
BEGIN
SET NOCOUNT ON
SET XACT_ABORT ON
DECLARE @ID bigint
DECLARE @TimeStamp timestamp
DECLARE @hDoc int
EXEC sp_xml_PrepareDocument @hDoc OUT, @XMLDoc
SELECT @ID = ID
,@TimeStamp = [TimeStamp]
FROM OPENXML (@hdoc,'/XML')
WITH ( ID bigint 'ID'
,[TimeStamp] timestamp 'TStamp')
IF @@ERROR<>0
BEGIN
EXEC sp_xml_RemoveDocument @hDoc
SELECT -620 AS RetVal
RETURN
END
IF NOT EXISTS(SELECT 1 FROM Table1 WHERE ID= @ID AND Timestamp = @TimeStamp )
BEGIN
SELECT -1 AS RetVal
END
ELSE
BEGIN
SELECT 1 AS RetVal
END
END
I have a table named Table1
which contains an ID
and TimeStamp
.
Table structure
ID TimeStamp
1 0x0000000000047509
But when I compare the combination of these fields, it always shows false. What is the reason for this?
My Query is :
DECLARE @ID int
DECLARE @TimeStamp timestamp
SET @ID = 1
SET @TimeStamp = 0x0000000000047509
If EXISTS(SELECT 1 FROM Table1 WHERE ID = @ID AND TimeStamP = @TimeStamp)
BEGIN
SELECT 1 AS RetVal
END
ELSE
BEGIN
SELECT -1 AS RetVal
END
My stored procedure is as follows
CREATE PROCEDURE [dbo].[Check] (
@XMLDoc ntext
)AS
BEGIN
SET NOCOUNT ON
SET XACT_ABORT ON
DECLARE @ID bigint
DECLARE @TimeStamp timestamp
DECLARE @hDoc int
EXEC sp_xml_PrepareDocument @hDoc OUT, @XMLDoc
SELECT @ID = ID
,@TimeStamp = [TimeStamp]
FROM OPENXML (@hdoc,'/XML')
WITH ( ID bigint 'ID'
,[TimeStamp] timestamp 'TStamp')
IF @@ERROR<>0
BEGIN
EXEC sp_xml_RemoveDocument @hDoc
SELECT -620 AS RetVal
RETURN
END
IF NOT EXISTS(SELECT 1 FROM Table1 WHERE ID= @ID AND Timestamp = @TimeStamp )
BEGIN
SELECT -1 AS RetVal
END
ELSE
BEGIN
SELECT 1 AS RetVal
END
END
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这很奇怪,这个查询在 SQL Server 2005、兼容模式 80 中对我来说工作得很好。
唯一让我想到的是
Timestamp
是一个保留字,所以为了安全起见,你可能会想要在Timestamp
周围添加括号来转义它,如下所示:That's odd, the query works fine for me in SQL Server 2005, compatibility mode 80.
The only thing that jumps out to me is that
Timestamp
is a reserved word, so to be on the safe side you might want to add brackets aroundTimestamp
to escape it as follows:@TimeStamp 未从 XML 中正确解析。尝试将其转换为二进制(8)。
存储过程与您之前发布的查询不匹配
@TimeStamp is not being resolved correctly from the XML. Try CASTing it to binary(8).
The stored proc does not match the query you posted earlier