SQL Notes
SQL Notes
use db_Test
sum
avg
min
max
count = count particular column value cannot count null value
Numeric Function
ABS means absolute function
select ABS(-10)
select CEILING(78.5)
select FLOOR(78.9)
select SIGN(12), SIGN(-12), SIGN(0) return 1 when value is positive -1 when value
is negative and zero in case of 0
///string function
//Boolean function
//group by
select deptno, sum(Salary) as 'Total salary' from person group by deptno Having =20
select deptno, sum(Salary) as 'Total salary' from person where deptno = 20 group by
deptno
//Top() clause
the Top clause specifies the first n rows of the query result that are to be
retrived.
this clause should always be used with the order by clause
return multiple rows.
//Alter(DDL)
alter table emp add projected_complted int not null default5 decimal not null
alter table emp add salary decimal not null
alter table emp add projectID integer null constraints pID_unique_key UNIQUE
//EXCEPT Operator:
The EXCEPT operator will return unique rows from the left query that aren’t present
in the right query’s results.
//self join
use db_test
---self join
---function
create Function [dbo].[Sum]
(
@num1 int,
@num2 int
)
Returns int
As
begin
Declare @Result int
select @Result = @num1 +@num2
return @Result
End
create proc[dbo].[callFunction]
@FirstNum int,
@SecondNum int
As
Begin
select dbo.[sum](@FirstNum,@SecondNum)
End
[callFunction] 2,3