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
set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON go
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