今天在工作中被一个知识点难住了,就是写sql语句,分支语句个sql中的类型转换。哎很简单的知识点哎,憋了一下午 ,收获就是sql语句也是可以断定调试的,还可以单独的将句子摘出来执行下,看看运行结果
--declare @CatayCode varchar(50)
--set @CatayCode=( select CatayCode from item where id=9)
insert into item values (0,119,'美丽护肤3')
declare @count int ,@CatayCode varchar(50)
set @count =(select COUNT(CatayCode) from item where ParentId=20)if @count=0
begin
set @CatayCode=( select CatayCode from item where id=20)+'001'
end
else
begin
set @CatayCode= (select MAX (cast(right(CatayCode,6) as int)) from item where ParentId=20)+1
end
insert into item values (20,@CatayCode,'我爱你啊')
select * from item
select MAX (cast(right(CatayCode,6) as int)) from item where ParentId=9
select MAX (id) from item where ParentId=9