日期:2014-05-18  浏览次数:20523 次

动态SQL执行【在线等】
SQL code
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON 
GO



ALTER    PROCEDURE [dbo].[SP_DEPOT_SELECT]
@P_MobileId nvarchar(50)
AS
declare @sqlstr nvarchar(4000)
DECLARE @PhoneCount int
DECLARE    @return_DateTime int
declare @DepotCount int
BEGIN
                    --将这条操作数据标示为当前用户
            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,N'@P_MobileId nvarchar(50)',@P_MobileId
            commit
END



GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO



上面哪个@sqlstr变量的值被截取成UPDATE [Depot] with(rowlock) SET [LockFlag] = @P_MobileId, LockDate = getdate() WHERE ID=(SELECT top(1)Id FROM depot where [Loc是为什么

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

引用:
上面哪个@sqlstr变量的值被截取成UPDATE [Depot] with(rowlock) SET [LockFlag] = @P_MobileId, LockDate = getdate() WHERE ID=(SELECT top(1)Id FROM depot where [Loc是为什么

除非你的@sqlstr 不够长(你是4000)不可能……

------解决方案--------------------
SQL code

ALTER PROCEDURE [dbo].[SP_DEPOT_SELECT]
@P_MobileId nvarchar(50)
AS
declare @sqlstr nvarchar(4000)
DECLARE @PhoneCount int
DECLARE @return_DateTime int
declare @DepotCount int
BEGIN
                    --将这条操作数据标示为当前用户
            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,N'@P_MobileId nvarchar(50)',@P_MobileId
            commit tran
END

------解决方案--------------------
参考:
http://topic.csdn.net/t/20040417/18/2977759.html

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