http://www.teecool.com/post/2007071808.html
http://blog.csdn.net/zhangyj_315/category/375024.aspx
http://blog.csdn.net/m_yeah/archive/2009/02/19/3908885.aspx
select datepart(dd,
dateadd(dd,
-1,
dateadd(mm,1,cast(cast(year(getdate()) as varchar)+'-'+cast(month(getdate()) as varchar)+'-01' as datetime))))
go
declare @now datetime
set @now = '2009-07-21'
select day(dateadd(dd,-1,dateadd(mm,1,cast(cast(year(@now) as varchar) + '-' + cast(month(@now) as varchar) + '-01' as datetime))))
select day(dateadd(dd,-1,dateadd(mm,1,cast(cast(year(getdate()) as varchar)+'-'+cast(month(getdate()) as varchar)+'-01' as datetime))))
go
create table BookInfo(
BookId int,
BookName varchar(50),
Price float)
insert BookInfo values(1,'Windows Internals',20)
insert BookInfo values(2,'Linker & Loader',10)
insert BookInfo values(3,'Design Pattern',5)
insert BookInfo values(4,'Design Pattern',null)
insert BookInfo(BookId,BookName) values(5,'Common Sence')
select BookId,BookName,Price
from BookInfo
select BookId,BookName,Price=case when Price is null then 'UnKnown' when Price between 10 and 20 then '10-20' else 'Others' end
from BookInfo
select BookName
from( select BookName, count(BookName) as num
from BookInfo
group by BookName) T1
where T1.num >= 2
select * from BookInfo
select row_number() over( order by Price asc) as line_no , *
from BookInfo
select BookId, BookName,Price into #Temp1
from(
select row_number() over( order by Price asc) as line_no , *
from BookInfo) T1
where line_no between 2 and 4
select * from #temp1
truncate table BookInfo
select * into #Temp2 from BookInfo
insert into BookInfo
select * from #temp1
insert into BookInfo
select * from #temp2
drop table #temp1
drop table #temp2
Create table T1(
id int,
num int)
create table T2(
id int,
s_name varchar(20))
insert into T1 values(1,100)
insert into T1 values(2,200)
insert into T1 values(3,300)
insert into T1 values(4,400)
insert into T2 values(3,'AAAA');
insert into T2 values(4,'BBBB');
insert into T2 values(5,'CCCC');
insert into T2 values(6,'DDDD');
select * from T1
select * from T2
select * from T1 inner join T2 on T1.id = T2.id
select * from T1 join T2 on T1.id = T2.id
select * from T1 left join T2 on T1.id = T2.id
select * from T1 left outer join T2 on T1.id = T2.id
select * from T1 right join T2 on T1.id = T2.id
select * from T1 right outer join T2 on T1.id = T2.id