SQL SERVER 新建标量函数,表,存储过程,查询练习
作者:互联网
CREATE FUNCTION English_GetFormatDate(@Date DateTime)
RETURNS varchar(100)
AS
BEGIN
RETURN LEFT (datename(month,@Date),3 )+ ''+ltrim(day(@Date))+ ',' +datename(year,@Date)
END
格式二:05/17/2021
CREATE FUNCTION Chinese_GetFormatDate(@Date DateTime)
RETURNS varchar(100)
AS
BEGIN
RETURN CONVERT(varchar(100),@Date,101)
END
建表
create table Date_Log (
id int identity (1,1) primary key,
date_format_one varchar(100) ,
date_format_two varchar(100) ,
current_datetime SMALLDATETIME DEFAULT(GETDATE())
)
删除存储过程 drop procedure usp_AddLog
创建存储过程
CREATE PROC usp_AddLog @Date DateTime
AS
BEGIN
INSERT INTO Date_Log (id, date_format_one,date_format_two) VALUES ([dbo].[English_GetFormatDate](@Date),[dbo].[Chinese_GetFormatDate](@Date))
END
执行存储过程
declare @Date Date =GETDATE()
exec [dbo].[usp_AddLog] @Date
declare @Date Date ='2021-05-12'
exec [dbo].[usp_AddLog] @Date
查看最后5条数据
select TOP 5 * from [TestDB].[dbo].[Date_Log] order by id desc
标签:usp,varchar,dbo,AddLog,SERVER,Date,SQL,标量,100 来源: https://www.cnblogs.com/0624zfz/p/16280516.html