源程序:
ALTER proc GetDataByNumCategory
(
@Carcategory nvarchar(50)
)
as
declare @sql nvarchar(1000)
declare @Num nvarchar(20)
set @Num=(select top 1 Keyword from TaoCarActive)
declare @Green nvarchar(100)
declare @Green1 nvarchar(100)
set @Green='<span style="color:Green;">'
set @Green1='</span>'
declare @Red nvarchar(100)
set @Red='<span style="color:Red;">'
declare @Red1 nvarchar(100)
set @Red1='</span>'
exec('select top '+@Num+'
ID,
case when Hits=0 then '''+@Green+'''+CarCard+'''+@Green1+'''
else '''+@Red+'''+CarCard+'''+@Red1+''' end as CarCard
from
TaoCarActive where Carcategory='''+@Carcategory+''' order by ID')