关于存储过程中二进制或运算的问题
大家好,请教大家一下,我在存储过程中,需要对两个二进制数进行按位或运算,但是系统报错:“数据类型 binary 和 binary 在 boolean OR 运算符中不兼容。”
请各位高手指教!!!
具体代码如下:
set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
go
Alter PROCEDURE [dbo].[CollectSchedulDataMonitor]
@result binary(16) = 0x0000000000000000 output
AS
Declare @PLCId int
Declare @Tagid int
Declare @Value float
Declare @stime datetime
Declare @etime datetime
Declare @countErr int
Declare @count int
Declare @flag binary(16)
Declare @org binary(16)
set @etime=getdate()
set @stime=dateadd(n,-15,@etime)
set @flag = 0x0000000000000001
set @org = 0x0000000000000000
set @PLCId=1
While @PLCId<=10
Begin
set @countErr = 0
set @count = 0
Declare tagidCursor Cursor For
Select Tagid From Controldata.CollectScheduleDataDictionary Where PLCId=@PLCId
Open tagidCursor
Fetch Next From tagidCursor Into @Tagid
While @@FETCH_STATUS = 0
Begin
Declare dataValueCursor Cursor For
Select value From ControLdata.Monitor Where tagid = @Tagid And logtime Between @stime And @etime
Fetch Next From dataValueCursor Into @Value
Open dataValueCursor
While @@FETCH_STATUS =0
Begin
set @count = @count + 1
If @Value = Null
Begin
set @countErr = @countErr + 1
End
Fetch Next From dataValueCursor Into @Value
End
Close dataValueCursor
DealLocate dataValueCursor
If(@countErr/@count > 0.2)
Begin
Set @org = @org | @flag
End
Set @flag = @flag * 2
Fetch Next From tagidCursor Into @Tagid
End
Close tagidCursor
DealLocate tagidCursor
End
Return @result
其中错误语句:是Set @org = @org | @flag
另外,SQL中是否不支持位左移呢?我只好用Set @flag = @flag*2 来实现左移
[解决办法]
参考 http://bbs.csdn.net/topics/70145770
[解决办法]