/* 表名 Soft 列: ID、img 要求一条SQL查询语句,当IMG列不为空时,返回IMG列的值,若为空时(null),返回img列的值为1234 要怎么实现 不带判断我知道可能用 as 稍复杂点的就不太清楚了 */ declare @TT table ( ID int identity(1,1) primary key, img varchar(20) ) insert into @TT select '2121221.jpg' insert into @TT select '2121221.gif' insert into @TT select '' insert into @TT select '212122dadad1.gif'if exists(select count(*) from @TT where len(img)>0) begin select * from @TT where len(img)>0 end else begin update @TT set img='1234' end ID img ----------- -------------------- 1 2121221.jpg 2 2121221.gif 4 212122dadad1.gif(所影响的行数为 3 行)
select [img]=case when img is null then 1234 else img end from soft
<asp:Image ID="Image1" runat="server" ImageUrl=' <%# Eval("softimg").ToString==""?"~/images/empty.jpg":"~/upimg/"+Eval("path")+"/"+Eval("softimg")%>'/>就行了。
表名 Soft 列: ID、img 要求一条SQL查询语句,当IMG列不为空时,返回IMG列的值,若为空时(null),返回img列的值为1234 要怎么实现 不带判断我知道可能用 as 稍复杂点的就不太清楚了
*/
declare @TT table
(
ID int identity(1,1) primary key,
img varchar(20)
)
insert into @TT select '2121221.jpg'
insert into @TT select '2121221.gif'
insert into @TT select ''
insert into @TT select '212122dadad1.gif'if exists(select count(*) from @TT where len(img)>0)
begin
select * from @TT where len(img)>0
end
else
begin
update @TT set img='1234'
end
ID img
----------- --------------------
1 2121221.jpg
2 2121221.gif
4 212122dadad1.gif(所影响的行数为 3 行)
但这种方式对于空值不处理。。