用就不说了,上搜索上查一下,本示例就简单一些代码。动态执行SQL语句输出值
DECLARE @sqlsen NVARCHAR(2000),
@table VARCHAR(30),
@Ifexist VARCHAR(20),
@TelType TINYINT,
@CustomerTelmd5 VARCHAR(32),
@ParmDefinition NVARCHAR(500);
SET @table ='xueit.dbo.表' + RIGHT(@CustomerTel, 2)
SET @sqlsen ='select @Ifexist =字段,@CID=字段1,@TelType=字段2
from ' + @table + ' where 表 =''' + @CustomerTel + ''''
SET @ParmDefinition = N'@Ifexist varchar(20) OUTPUT,@CD int OUTPUT,@TelType tinyint OUTPUT'
EXEC sp_Executesql
@sqlsen,
@ParmDefinition,
@Ifexist OUTPUT,
@CustomerID OUTPUT,
@TelType OUTPUT