SQL Server 2000 中的时间戳

发布于 2024-09-26 15:40:39 字数 1233 浏览 4 评论 0原文

我有一个名为 Table1 的表,其中包含 IDTimeStamp

表结构

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

情绪操控生活 2024-10-03 15:40:39

这很奇怪,这个查询在 SQL Server 2005、兼容模式 80 中对我来说工作得很好。

唯一让我想到的是 Timestamp 是一个保留字,所以为了安全起见,你可能会想要在 Timestamp 周围添加括号来转义它,如下所示:

If EXISTS(SELECT 1 FROM Table1 WHERE [ID] = @ID AND [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 around Timestamp to escape it as follows:

If EXISTS(SELECT 1 FROM Table1 WHERE [ID] = @ID AND [TimeStamP] = @TimeStamp) ...
千仐 2024-10-03 15:40:39

@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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文