sql server中的exec和sp_executesql
参考地址:http://www.cnblogs.com/xbf321/archive/2008/11/02/1325067.html
exec('select * from TableName')
declare @slideAvg real declare @sql1 nvarchar(1000) set @sql1='select @slideAvg=avg(val) from S'+@StationID+'HN where channel_num='''+@channel_num+''' and date_time>='''+convert(nvarchar,@oldH,120)+''' and date_time<='''+convert(nvarchar,@h24,120)+'''' exec sp_executesql @sql1,N'@slideAvg real output',@slideAvg output IF @slideAvg IS NOT NULL AND @slideAvg<>'' begin ......... end
SELECT C0252_ID, C0252_name,C0252_Addr, ((select top 1 C0003_Name from dbo.T0003_DistrictInfo where c0003_code like '%'+SUBSTRING(C0003_AreaCode,1,4)+'%')+' '+C0003_AreaName) as AreaName FROM dbo.T0252_Manufacturer