当前位置: 代码迷 >> Sql Server >> 动态SQL执行【】
  详细解决方案

动态SQL执行【】

热度:82   发布时间:2016-04-27 14:44:52.0
动态SQL执行【在线等】
SQL code
SET QUOTED_IDENTIFIER ON GOSET ANSI_NULLS ON GOALTER    PROCEDURE [dbo].[SP_DEPOT_SELECT]@P_MobileId nvarchar(50)ASdeclare @sqlstr nvarchar(4000)DECLARE @PhoneCount intDECLARE    @return_DateTime intdeclare @DepotCount intBEGIN                    --将这条操作数据标示为当前用户            begin tran            set @sqlstr = ''            set @sqlstr = 'UPDATE [Depot] with(rowlock) SET [LockFlag] = @P_MobileId, LockDate = getdate() WHERE ID=(SELECT top(1)Id FROM depot where [LockFlag] is null or [LockFlag] = '''''                        exec sp_executesql @sqlstr,[email protected]_MobileId nvarchar(50)',@P_MobileId            commitENDGOSET QUOTED_IDENTIFIER OFF GOSET ANSI_NULLS ON GO

[email protected] [Depot] with(rowlock) SET [LockFlag] = @P_MobileId, LockDate = getdate() WHERE ID=(SELECT top(1)Id FROM depot where [Loc是为什么

------解决方案--------------------
探讨

引用:
[email protected] [Depot] with(rowlock) SET [LockFlag] = @P_MobileId, LockDate = getdate() WHERE ID=(SELECT top(1)Id FROM depot where [Loc是为什么

[email protected] 不够长(你是4000)不可能……

------解决方案--------------------
SQL code
ALTER PROCEDURE [dbo].[SP_DEPOT_SELECT]@P_MobileId nvarchar(50)ASdeclare @sqlstr nvarchar(4000)DECLARE @PhoneCount intDECLARE @return_DateTime intdeclare @DepotCount intBEGIN                    --将这条操作数据标示为当前用户            begin tran            set @sqlstr = ''            set @sqlstr = 'UPDATE [Depot] with(rowlock) SET [LockFlag] = @P_MobileId, LockDate = getdate() WHERE ID=(SELECT top(1)Id FROM depot where [LockFlag] is null or [LockFlag] = '''')'                        exec sp_executesql @sqlstr,[email protected]_MobileId nvarchar(50)',@P_MobileId            commit tranEND
------解决方案--------------------
参考:
http://topic.csdn.net/t/20040417/18/2977759.html

如果数据库中执行正常的话,你有可能是在程序中被截断了,断点调试一下。
  相关解决方案