日期:2014-05-18 浏览次数:20593 次
select NewsID,title,content,p_date, visitURL='item-'+ltrim(row_number()over(partition by p_date order by getdate())) from News
------解决方案--------------------
create table News(NewsID int,title varchar(8),content varchar(15),p_date date,visitURL varchar(6)) insert into News select 1,'title1','content1','2011-10-18','' union all select 2,'title1','content1','2011-10-18','' union all select 3,'title1','content1','2011-10-18','' union all select 4,'title1','content1','2011-10-18','' union all select 5,'title1','content1','2011-10-19','' union all select 6,'title1','content1','2011-10-19','' union all select 7,'title1','content1','2011-10-19','' union all select 8,'title1','content1','2011-10-19','' union all select 9,'title1','content1','2011-10-19','' update a set a.visitURL='item-'+cast(b.s as varchar) from News a inner join (select NewsID,row_number() over(partition by p_date order by NewsID) s from News) b on a.NewsID=b.NewsID select * from News NewsID title content p_date visitURL ----------- -------- --------------- ---------- -------- 1 title1 content1 2011-10-18 item-1 2 title1 content1 2011-10-18 item-2 3 title1 content1 2011-10-18 item-3 4 title1 content1 2011-10-18 item-4 5 title1 content1 2011-10-19 item-1 6 title1 content1 2011-10-19 item-2 7 title1 content1 2011-10-19 item-3 8 title1 content1 2011-10-19 item-4 9 title1 content1 2011-10-19 item-5