Beruflich Dokumente
Kultur Dokumente
empno integer
, ename varchar(10)
, sal decimal(13,4)
, comm decimal(13,7)
);
insert into emp_sal_3 values (100, 'rama', 10000.15, 100);
insert into emp_sal_3 values (200, 'mac', 20000, 150), (300, 'jorrit', 8000.75,
NULL);
insert into emp_sal_3 values (400, 'rama', 17000.22, 200);
update emp_sal_3
set location = 'BNG'
;
update emp_sal_3
set comm = 1
where empno = 300 and location = 'BNG'
;
insert into emp_sal_3 values (500, 'hans', 19000, 200, 'pune'), (600, 'harm',
19000, 200, 'delhi');
select deptno, sal, empno, ename from emp where deptno <> 10;
select deptno, sal, empno, ename from emp where deptno <> 10 order by deptno;
select deptno, sal, empno, ename from emp order by deptno where deptno <> 10;
select deptno, sum(sal) sal from emp where deptno <> 10 group by empno;
select deptno, sum(sal) sal from emp group by deptno where deptno <> 10;
select deptno, sum(sal) sal from emp where deptno <> 10 having sum(sal) > 4000;
select deptno, sum(sal) sal from emp where deptno <> 10 group by deptno having
sum(sal) > 4000;
select deptno, sum(sal) sal from emp where deptno <> 10 having sum(sal) > 4000
group by deptno;
select deptno, sum(sal) sal from emp where deptno <> 10 order by deptno having
sum(sal) > 4000 group by deptno ;
select empno, ename, sal, comm, sal+isnull(comm, 100000) from emp; --error
select empno, ename, sal, comm from emp where comm = NULL;
select empno, ename, sal, comm from emp where comm IS NULL;
select empno, ename, sal, comm from emp where comm IS not NULL;
select abs(-16.78);
select abs(-998.7878956) ;
select abs(123416.786789) ;
select abs(0) ;
select abs(NULL) ;
select sign(-16.78) ;
select sign(-998.7878956) ;
select sign(123416.786789) ;
select sign(NULL) ;
select lower(upper('database')) ;
select upper(lower('database')) ;
SELECT CHARINDEX('A','DATABASE') ;
SELECT CHARINDEX('A','DATABASE') ;
SELECT CHARINDEX('A','DATABASE', 2) ;
SELECT CHARINDEX('A','DATABASE', 3) ;
http://www.sql-server-helper.com/faq/oracle-functions-p01.aspx
http://sqltrim.codeplex.com/SourceControl/latest#trim_test.sql
SELECT LTRIM('00000000012345','0') "value" ; --syntax wrong
select max(sal) from emp where sal < (select max(sal) from emp);
select sal from emp a where 4 = (select count(sal) from emp b where a.sal <=
b.sal);
select sal from emp a where 2 = (select count(sal) from emp b where a.sal <=
b.sal);
select sal from emp a where 12 = (select count(sal) from emp b where a.sal <=
b.sal);
select sal from emp a where 3 = (select count(distinct sal) from emp b where a.sal
<= b.sal);
select sal from emp a where 2 = (select count(distinct sal) from emp b where a.sal
<= b.sal);
select sal from emp a where 9 = (select count(distinct sal) from emp b where a.sal
<= b.sal);
select sal from emp a where 9 = (select count(distinct sal) from emp b where a.sal
>= b.sal);
select empno, ename, sal, deptno, rank() over(order by sal) rn from emp;
select empno, ename, sal, deptno, rank() over(order by sal desc) rn from emp;
select empno, ename, sal, deptno, dense_rank() over(order by sal) rn from emp;
select empno, ename, sal, deptno, dense_rank() over(order by sal desc) rn from emp;
select empno, ename, sal, deptno, rank() over(order by sal desc) rn from emp
where rn = 2;
select a.* from (select empno, ename, sal, deptno, rank() over(order by sal desc)
rn from emp) a
where rn = 2;
select b.* from (select empno, ename, sal, deptno, rank() over(order by sal desc)
rn from emp) b
where rn = 2 or rn = 6;
select b.empno, b.ename, b.sal, b.deptno from (select empno, ename, sal, deptno,
rank() over(order by sal desc) rn from emp) b
where rn = 3 or rn = 6;
select empno, ename, sal, deptno, rank() over(partition by deptno order by sal
desc) rn from emp;
select empno, ename, sal, sum(sal) over(order by sal) cume from emp;
---NO DECODE---
select GETDATE() ;
select GETDATE()+1 ;
select GETDATE()-11 ;
select last_day(GETDATE()) ;
select DAY(getdate())
select month(getdate())
select year(getdate())
select year(CURRENT_TIMESTAMP)
select datename(dw,getdate())
SELECT REPLICATE('_', 5) ;
select ascii('a') ;
select ascii('A') ;
select ascii('A12345') ;
select char(65) ;
select char(39) ;
SELECT PATINDEX('%@%','arrigologix@gmail.com')
SELECT PATINDEX('%@%','arrigologix@gmail.com')-1
SELECT SUBSTRING('arrigologix@gmail.com',
PATINDEX('%@%','arrigologix@gmail.com')+1,
DATALENGTH('arrigologix@gmail.com') -
PATINDEX('%@%','arrigologix@gmail.com')
)
SELECT SUBSTRING(@name,
PATINDEX('%@%',@name)+1,
DATALENGTH(@name) -
PATINDEX('%@%',@name)
)
select ceiling(3456.7890) ;
select ceiling(56.001) ;
select ceiling(-98.001) ;
select floor(3456.7890) ;
select floor(56.001) ;
select floor(-98.001) ;
select round(4583478.12381, 1) ;
select round(4583478.512381, 1) ;
select round(4583478.512381, 0) ;
select round(4583478.512381, 2) ;
select round(4583478.512381, 2, 1) ;
select round(4583478.512381, 4) ;
select round(4583478.512381, 4, 2) ;
select round(4583478.512381, 4, 1) ;
update emp_view111
set sal = 10000;
update emp_view2
set sal = 10000;
insert into cust_d1 (ID, NAME, LOCATION, ADDRESS) values (3, 'CCC', 'HYD',
'TELANgANA');
insert into cust_d1 (ID, NAME, LOCATION) values (6, 'EEE', 'DEL');
insert into cust_d1 (ID, NAME, LOCATION, ADDRESS) values (9, 'CCC', 'HYD',
'TELANgANA');
ID integer,
NAME varchar(50),
SAL decimal(11,2),
LOCATION varchar(10),
ADDRESS varchar(20)
);
ID integer,
NAME varchar(50),
SAL decimal(11,2),
LOCATION varchar(10),
AGE integer
);
alter table cust_p1 add constraint cust_p1_id_age primary key (id, age);
ID integer,
NAME varchar(50),
SAL decimal(11,2),
LOCATION varchar(10),
AGE integer
);
select * from (
select a.empno, a.ename, a.sal sal, b.ename mgr_name, b.sal mgr_sal from emp a, emp
b
where a.mgr = b.empno) t
where t.sal > t.mgr_sal;
select empno, count(*) from emp group by empno having count(*) > 1;
select * from emp where sal >= 1000 and sal <= 4500;
select * from emp where sal >= 1000 or sal <= 4500;
select ISNUMERIC(123)
select ISNUMERIC('123')
select ISNUMERIC('123a')
select isdate(getdate())
select isdate('123')
SELECT ISDATE('2015-05-01')
go
go
SELECT *,
HouseNumber + ' '
+ StreetName + ' ' + City + ' ' + State AS FullStreetAddress
FROM dbo.CustomerAddress
--Use ISNULL To Handle Null Contatenation in SQL Serve when using Plus Sign
SELECT *,
Isnull(Cast(HouseNumber AS VARCHAR(10)), '')
+ ' ' + StreetName + ' ' + City + ' ' + State AS FullStreetAddress
FROM dbo.CustomerAddress
AS FullStreetAddress
FROM dbo.CustomerAddress
AS FullAddress
from dbo.CustomerAddress
dbcc useroptions
AS FullAddress,
ISNULL(State,'Unknow') AS StateAvailableOrNot
from dbo.CustomerAddress
AS FullAddress,
Case
When State is null Then 'Unknown' ELSE State END AS StateAvailableOrNot
from dbo.CustomerAddress
SELECT TOP(5) *
FROM emp
WHERE sal <= 4000;
SELECT TOP(25) PERCENT *
FROM emp
WHERE sal <= 4000;
DELETE TOP(5)
FROM emp
WHERE sal <= 4000;