表partInfo ID partType -------------------------- pt001 A1 pt001 A1/A2 pt002 B1 pt002 B2 ------------------------- 要求结果 ID partType -------------------------- pt001 A1/A2 pt002 B1/B2给个说明或方法,结果怎么来的? create function f_str(@id varchar(10)) returns varchar(1000) as begin declare @s varchar(1000) select @s = isnull(@s+'/','')+case when charindex('/'+parttype+'/','/'+@s+'/')>0 then '' else parttype end from partinfo where id = @id return @s end go
select id,dbo.f_str(id) from from partinfo group by id
速度太快了 不行,还是先折分 SQL code: ---------------------------------------------------------------- -- Author :fredrickhu(小F,向高手学习) -- Date :2010-04-02 16:47:45 -- Verstion: -- Microsoft SQL Server 2005 - 9.00.4053.00 (Intel X86)
update test set qty = qty - 1 where (location,sku,valid_date) in (select location,sku,min(valid_date) from test where location = 'chuwei' and item_code = '5678' group by location,sku) 以上语 ......