我有一个将数据推送到我的数据库的过程。数据库中的一个表用于存储我从进程获得的用户(tblUsers
)(该进程与云通信)。
tblUsers
的列是:
sid - id1 - id2 - userId - username - timestampt
将数据推入此表后,我有几个条目,其中sid,id1,id2,userid和username相等。为了消除它们,我使用以下SQL语句:
DECLARE @tbl table
(
sid int,
id1 int,
id2 int,
userId int,
userName varchar(40),
timestamp char(14),
rn int
)
insert into @tbl
select
*,
ROW_NUMBER() over (partition by id1, id2, userId, userName order by timestamp desc) as rn
from dbo.tblUsers
update r
set r.userIdRef = t2.sid
from dbo.tblContracts r
join @tbl t1 on r.userIdRef = t1.sid
join @tbl t2 on t1.id1 = t2.id1
and t1.id2 = t2.id2
and t1.userId = t2.userId
and t1.userName = t2.userName
and t1.sid <> t2.sid
and t2.rn = 1
update r
set r.userIdRef = t2.sid
from dbo.tblTimes r
join @tbl t1 on r.userIdRef = t1.sid
join @tbl t2 on t1.id1 = t2.id1
and t1.id2 = t2.id2
and t1.userId = t2.userId
and t1.userName = t2.userName
and t1.sid <> t2.sid
and t2.rn = 1
delete m
from dbo.tblUsers m
join @tbl t on m.sid = t.sid
where t.rn > 1
如果我直接在SQL Server 2008 Management Studio中调用它,它就可以正常工作。
如果我使用此代码创建存储过程并在Management Studio中调用它,它也可以正常工作。
现在,如果我从C ++应用程序调用存储过程,它就不起作用了。当我调用-1
句柄有效时,我收到错误代码SQLRETURN rc = SQLExecute(sqlHandle);
。我已经检查过了。
有人能告诉我这方面的问题是什么吗?