-
Notifications
You must be signed in to change notification settings - Fork 0
/
shoppingmall_CREATEFUNCTİON.sql
78 lines (47 loc) · 1.58 KB
/
shoppingmall_CREATEFUNCTİON.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
use ShoppingMall
----USER DEFÝNED FUNCTÝON------
go
Create Function KDVhesapla(@fiyat money) -- parameter(one or more ) + type
returns money -- can be return type
begin
return @fiyat*1.08
end;
go
-- go go : you can removes redness if your cade successfully
select ProductName,
CategoryName,
UnitPrice,
dbo.KDVhesapla( UnitPrice) as [KDV] -- IF you write function . you should write ' dbo'
from Products P
join Categories C on p.CategoryID=c.ID
order by 4
go
Create function Age (@birthdate datetime)
returns int
begin
return DateDiff (YY,@birthdate,getdate())
end;
go
select FirstName+''+LastName as [Full name ] ,dbo.Age( BirthDate) as age
from Customers
order by age desc
--TABLE FUNCTÝON--
create function CustomerInformation(@customerID int)
returns table
return select * from Customers where ID= @customerID
select * from CustomerInformation(5)
create function stock (@started int , @finished int )
returns table
return select * from Products where UnitInStock between @started and @finished
select * from stock(50,100)
-- if you will update anywhere of function, you can use ""ALTER "
Alter function stock (@started smallint , @finished smallint )
returns table
return select * from Products where UnitInStock between @started and @finished
select * from stock(50,100)
Create function GetStartWord(@Firstword nVarchar(1) )
returns table
return select * from Customers
where LEFT(FirstName ,1) =@Firstword
select * from GetStartWord('R')
-