日期:2014-05-17 浏览次数:20556 次
declare @icount int declare @sql nvarchar(2000) set @sql = 'select @icount=count(crmcustomerid) from ' + @tablename + ' where crmcustomerid = ' + cast(@pi_iCrmcustomerId as varchar) exec sp_executesql @sql,N'@icount int output',@icount output select @icount as a if @icount > 0 ...........
declare @icount int declare @sql nvarchar(2000) set @sql = 'select '+cast(@icount as varchar(10))+'=count(crmcustomerid) from ' + @tablename + ' where crmcustomerid = ' + cast(@pi_iCrmcustomerId as varchar) exec sp_executesql @sql,N'@icount int output',@icount output select @icount as a if @icount > 0
------解决方案--------------------
如果磊仔的没问题我就不说了
------解决方案--------------------
语法应该没什么错误的。
------解决方案--------------------
------解决方案--------------------
2008里 测试楼主代码 没有任何问题啊
create proc P_TEST
as
declare @tablename varchar(200)='TBA'
declare @icount int
declare @sql nvarchar(2000)
set @sql = 'select @icount=count(a) from ' + @tablename
exec sp_executesql @sql,N'@icount int output',@icount output
select @icount as a
if @icount > 0
print 'OK'
------解决方案--------------------
你那个crmcustomerid字段是什么类型?
------解决方案--------------------
最好先确定下 是哪个@icount出了问题。
declare @icount int
declare @TI int
declare @sql nvarchar(2000)
set @sql = 'select '+cast(@icount as varchar(10))+'=count(crmcustomerid) from ' + @tablename + ' where crmcustomerid = ' + cast(@pi_iCrmcustomerId as varchar)
exec sp_executesql @sql,N'@icount int output',@icount output
select @icount as a
set @TI=@icount
if @TI> 0
------解决方案--------------------