日期:2014-05-17 浏览次数:20489 次
表teset
字段:
ID PY
1 A
2 B
3 A
4 D
5 C
6 B
7 1
8 A
9 A
10 A
Has="A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z"
'比如PY字段中有A
Response.Write "<a target=""_self"" href=""#a"">A</a>"
'如果没有A
Response.Write "A"
'如果有数字,则直接输出
Response.Write "1"
create table #tb(ID int,PY char(1))
insert into #tb
select 1,'A'
union all select 2,'B'
union all select 3,'A'
union all select 4,'D'
union all select 5,'C'
union all select 6,'B'
union all select 7,1
union all select 8,'A'
union all select 9,'A'
union all select 10,'A'
declare @Has varchar(1000)
set @Has='A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z'
select distinct case when charindex(','+cast(PY as varchar)+',',','+@Has+',')=0 then PY
else '"<a target=""_self"" href=""#a"">'+cast(PY as varchar)+'</a>"' end as result
from #tb
drop table #tb
--结果
/*
"<a target=""_self"" href=""#a"">A</a>"
"<a target=""_self"" href=""#a"">B</a>"
"<a target=""_self"" href=""#a"">C</a>"
"<a target=""_self"" href=""#a"">D</a>"