前往顾页
以后地位: 主页 > 收集编程 > .Net实例教程 >

SQL SERVER存储过程和函数利用

时候:2010-10-31 18:16来源:知行网www.zhixing123.cn 编辑:麦田守望者

create database test
go
use test
go
create procedure dbo.sp_formatdate -- 格局化输入日期
as
declare @year varchar(4)
declare @month varchar(2)
declare @day varchar(2)
declare @minute varchar(2)
declare @hour varchar(2)
declare @second varchar(2)
set @year = datepart(yy,getdate())
set @month = datepart(mm,getdate())
set @day = datepart(dd,getdate())
set @hour = datepart(hh,getdate())
set @minute = datepart(mi,getdate())
set @second = datepart(ss,getdate())
select @year + '-' + @month + '-' + @day + ' ' + @hour + ':' + @minute + ':' + @second

GO

================
CREATE function dbo.DateFormat
(
@date datetime
)
returns varchar(10)
as
begin
declare @year varchar(4),
@month varchar(2),
@day varchar(2),
@minute varchar(2),
@hour varchar(2),
@second varchar(2),
@result varchar(10)
set @year = datepart(yy,@date)
set @month = datepart(mm,@date)
set @day = datepart(dd,@date)
set @hour = datepart(hh,@date)
set @minute = datepart(mi,@date)
set @second = datepart(ss,@date)
set @result = @year + '-' + @month + '-' + @day + ' ' + @hour + ':' + @minute + ':' + @second
return @result
end

GO

 

------分开线----------------------------
标签(Tag):数据库 SQLServer2005
------分开线----------------------------
保举内容
猜你感兴趣