日期:2014-05-17 浏览次数:21033 次
--这是我在SQL 2005中写的SQL:
create table #tb(id int,tname nvarchar(10))
insert into #tb
select 1,'x' union all
select 2,'y'
begin
declare @i int
select @i = count(1) from #tb where id=1 and tname='a'
if @i = 0
begin
insert into #tb values (1,'a');
update #tb set tname='aa' where id=1 and tname='a'
end
select @i = count(1) from #tb where id=2 and tname='y'
if @i=0
begin
insert into #tb values (2,'y');
update #tb set tname='yy' where id=1 and tname='y'
end
select @i = count(1) from #tb where id=1 and tname='c'
if @i = 0
begin
insert into #tb values (1,'c');
update #tb set tname='cc' where id=1 and tname='c'
end
end
select * from #tb