1.EXEC 执行Sql语句被截断的问题:
Sql语句:
1 SET @sqlSel=‘SELECT ‘+@sqlField+‘, 2 SUM(ISNULL(b.customsTariff_Sup,0))AS customsTariff_Sup,SUM(ISNULL(addedValueTax_Sup,0))AS addedValueTax_Sup,SUM(ISNULL(ConsumptTax_Sup,0))AS ConsumptTax_Sup, 3 SUM(ISNULL(customsTariff_Ref,0))AS customsTariff_Ref,SUM(ISNULL(addedValueTax_Ref,0))AS addedValueTax_Ref,SUM(ISNULL(ConsumptTax_Ref,0))AS ConsumptTax_Ref, 4 SUM(ISNULL(customs_Sup,0)) AS customs_Sup,SUM(ISNULL(addedValue_Sup,0))AS addedValue_Sup,SUM(ISNULL(Consumpt_Sup,0))AS Consumpt_Sup, 5 SUM(ISNULL(customs_Ref,0)) AS customs_Ref,SUM(ISNULL(addedValue_Ref,0))AS addedValue_Ref,SUM(ISNULL(Consumpt_Ref,0))AS Consumpt_Ref, 6 SUM(ISNULL(customs_NoSupRef,0))AS customs_NoSupRef,SUM(ISNULL(addedValue_NoSupRef,0))AS addedValue_NoSupRef,SUM(ISNULL(Consumpt_NoSupRef,0))AS Consumpt_NoSupRef 7 from dbo.ClassifyCorrectionReportHead h 8 right join dbo.ClassifyCorrectionReportBody b on h.ID=b.HEADID 9 where ‘+@sqlWhere+‘ group by REPORTROWHEAD ‘ 10 11 print @sqlSel 12 exec @sqlSel --注释:@sqlSel 为变量 类型为 varchar(8000),@sqlField 为变量 类型为 varchar(500),@sqlWhere为变量 类型为 varchar(800)
在存储过程执行过程中发现错误“……无法识别的字符”:检查发现sql语句被截断,
.首先检查sql语句的长度是否超出变量定义的长度,(很明显没有超出)
.然后 sql语句能够完整打印出来,而且执行没错误,此时就可以判断是EXEC出现的问题了,
解决方案:
在执行的sql变量上加上();如:
exec (@sqlSel)
2. 高效清空表数据:TRUNCATE TABLE
与delete比较:
(1).DELETE
?DML语言
?可以回退
?可以有条件的删除
用法:DELETE FROM 表名
WHERE 条件
(2).TRUNCATE TABLE
?DD2.TRUNCATE TABLE
?DDL语言
?无法回退
?默认所有的表内容都删除
?删除速度比delete快。
用法:TRUNCATE TABLE 表名
时间: 2024-10-29 19:10:58