0

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

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

只要

4

1 回答 1

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

于 2012-10-24T15:32:58.243 回答