Sunday, 15 January 2012

some sql command

select len('siv')
select upper('siv')
select lower('SIV')
select day(getdate())
select month(getdate())
select year(getdate())
select DATEADD(DAY,1,GETDATE())
select DATEDIFF(DAY,GETDATE(),DATEADD(DAY,1,GETDATE()))
select DATEPART(DW,GETDATE())
select DATEADD(mi,1,GETDATE())
select convert(varchar(50),getdate(),103)
select replace(convert(varchar(50),getdate(),106),' ','-')
select charindex('%','siv%sankar')
select ltrim(' ram')
select rtrim('ram ')
select substring('ram',1,2)
select isnull(mgr,'0') from emp
select * from emp
select * from emp where name='x'
select * from emp where name='x' and eid=2
select * from emp where name='x' or eid=2
select * from emp where name!='x'
select * from emp where name like 'A%'
select * from emp where name like '_i%'
select top 2 * from emp
select * from emp order by sal desc
select distinct sal from emp
select newid(),* from emp
select row_number() over(order by sal desc) RANK,* from emp
select did,count(*) from emp group by did
select did,count(*) from emp group by did having count(*)>1
select *,MARK=case when did=10 then 'siv' when did=20 then 'sankar' else 'mahadev' end from emp
INSERT INTO F SELECT 4,'d' union select 5,'e' union select 6,'f'
select * from emp join dept on emp.did=dept.did
select * from emp left join dept on emp.did=dept.did
select * from emp right join dept on emp.did=dept.did
select * from emp full join dept on emp.did=dept.did
select * from emp cross join dept
select dname from emp join dept on emp.did=dept.did
select dname from emp right join dept on emp.did=dept.did where eid is null
select isnull(m.name,'')+' is working under '+isnull(t.name,'') from emp m join emp t on m.mgr=t.eid
select isnull(m.name,'')+' is working under '+isnull(t.name,'') from emp m gight join emp t on m.mgr=t.eid where m.name is null
select isnull(m.name,'')+' is working under '+isnull(t.name,'') from emp m left join emp t on m.mgr=t.eid where t.name is null
select * from emp where mgr=(select eid from emp where name='x')
select max(sal) from emp where sal<(select max(sal) from emp where sal<(select max(sal) from emp))
update f set name=(select name from ff where id=f.id) where id!=2

No comments:

Post a Comment