-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathFunctionTest.sql
More file actions
executable file
·51 lines (42 loc) · 991 Bytes
/
FunctionTest.sql
File metadata and controls
executable file
·51 lines (42 loc) · 991 Bytes
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
CREATE function Maximum(@x int,@y int)
returns int
as
begin
declare @big int
SELECT @BIG =CASE
WHEN @X>@Y THEN @X
ELSE @Y
END
--select @big as 'big'
return @big
end
declare @x as int
select @x=dbo.Maximum(1,2)
print @x
create function padZero(@str varchar(10))
returns varchar(2)
as
begin
if len(@str)=1
begin
return '0' + @str
end
else
begin
return @str
end
return ''
end
CREATE function formatDate(@date datetime)
returns varchar(200)
as
begin
return dbo.padZero(cast(month(@date) as varchar)) +'/' + dbo.padZero(datename(d,@date)) + '/' + datename(yyyy,@date) + ' ' + dbo.padZero(datename(hh,@date)) + ':' + dbo.padZero(datename(n,@date));
end
declare @x varchar(200)
select @x = dbo.formatDate('2003-03-26 19:00:00.000')
print @x
declare @y as datetime
select @y=GETDATE()
select @y,dbo.formatDate(@y)
select dbo.padZero('xx')