存储过程返回DateTime格式

时间:2012-10-24 15:29:20

标签: sql-server-2008 stored-procedures

我创建了一个存储过程,如下所示,

CREATE PROCEDURE [dbo].[Access_GetDate]
(
    @Name varchar(255)
)
AS
    SELECT TOP(1) Employee.StartDate 
    FROM Employee 
    WHERE Employee.Name = @Name;

它工作正常,但以这种格式返回日期

2012-10-24 00:00:00.000

但是我想用这种格式,

2012 10 24

1 个答案:

答案 0 :(得分:3)

您可以使用以下内容:

USE [DBNAME]
GO
CREATE PROCEDURE [dbo].[Access_GetDate]
(
    @Name varchar(255)
)
AS

SELECT TOP(1) replace(convert(char(10), Employee.StartDate, 120), '-', ' ') StartDate
FROM Employee 
WHERE Employee.Name = @Name;

请参阅SQL Fiddle with Demo