select t.id,t.name,(case when u.dt is null then t.dt else u.dt end)as updatedt from testta t left join
(select id,max(dt) as dt from updatedate group by id) as u on t.id=u.id
dt是时间

删除列:alter table testta drop column dt2
添加列及默认值:alter table testta add dt2 datetime constraint dt2 (default getdate() with values)

哪一月的每一天的数量是:
select convert(char(11),dt2),count(id) from testta where dt2 between convert(datetime,'04 01 2006') and convert(datetime,'05 01 2006')
group by convert(char(11),dt2)
convert(char(11),dt2):只取年月日

分页语句:
SELECT TOP pagesize * FROM articles
WHERE id NOT IN ( SELECT TOP ( pagesize * pageindex ) id FROM articles ORDER BY id DESC )
ORDER BY id DESC
pagesize:每页显示几条
pageindex:第几页

replace(字段名,char(13),'') 将字段中的回车符替换成为空

posted on 2008-08-26 13:35  pretty  阅读(173)  评论(0编辑  收藏  举报