go create trigger tri_tracy on tablename for insert as declare @id varchar(18) select @id=cardid from inserted if len(@id)=15 begin print substring(@id,6,8) end else begin print substring(@id,7,13) end
go if OBJECT_ID('fun_tracy')is not null drop function fun_tracy go create function fun_tracy(@date date) returns varchar as begin declare @str varchar(10) declare @year int,@month int select @year=year(@date),@month=month(@date) if @year%4=0 begin if (select charindex(ltrim(@month)+',','1,3,5,7,8.10.12'))>0 begin set @str='31天' end if @month=2 begin set @str='29天' end else begin set @str='30天' end end else if (select charindex(ltrim(@month)+',','1,3,5,7,8.10.12'))>0 begin set @str='31天' end if @month=2 begin set @str='28天' end else begin set @str='30天' end return @str end
Public Function tianshu(ByVal a As String) As Integer Dim iyear, imonth, iday As Integer iyear = Year(a) imonth = Month(a) If (iyear Mod 4 = 0) And (iyear Mod 100 = 0) Then iday = 1 ElseIf (iyear Mod 4 = 0) And (iyear Mod 100 <> 0) Then iday = 1 Else iday = 0 End If Select Case imonth Case 1, 3, 5, 7, 8, 10, 12 Return 31 Case 4, 6, 9, 11 Return 30 Case 2 If iday = 1 Then Return 29 Else Return 28 End If End Select End Function
go
create trigger tri_tracy on tablename
for insert
as
declare @id varchar(18)
select @id=cardid from inserted
if len(@id)=15
begin
print substring(@id,6,8)
end
else
begin
print substring(@id,7,13)
end
go
if OBJECT_ID('fun_tracy')is not null
drop function fun_tracy
go
create function fun_tracy(@date date)
returns varchar
as
begin
declare @str varchar(10)
declare @year int,@month int
select @year=year(@date),@month=month(@date)
if @year%4=0
begin
if (select charindex(ltrim(@month)+',','1,3,5,7,8.10.12'))>0
begin
set @str='31天'
end
if @month=2
begin
set @str='29天'
end
else
begin
set @str='30天'
end
end
else
if (select charindex(ltrim(@month)+',','1,3,5,7,8.10.12'))>0
begin
set @str='31天'
end
if @month=2
begin
set @str='28天'
end
else
begin
set @str='30天'
end
return @str
end
Dim iyear, imonth, iday As Integer
iyear = Year(a)
imonth = Month(a)
If (iyear Mod 4 = 0) And (iyear Mod 100 = 0) Then iday = 1
ElseIf (iyear Mod 4 = 0) And (iyear Mod 100 <> 0) Then
iday = 1
Else
iday = 0
End If
Select Case imonth
Case 1, 3, 5, 7, 8, 10, 12
Return 31
Case 4, 6, 9, 11
Return 30
Case 2
If iday = 1 Then
Return 29
Else
Return 28
End If
End Select
End Function