如何在SQL存储过程中将长日期格式更改为短日期格式

问题描述:

我已经在sql server 2008中创建了一个存储过程我想将长日期格式更改为短日期?



请急需帮助..项目正在进行中



我的尝试:



i have made a stored procedures in sql server 2008 i want to change the long date format into short date??

Please help need it urgently.. project is in process

What I have tried:

CREATE PROCEDURE [dbo].[OnelinePODate]
AS
BEGIN
	Select Main.Ibill_no,
       Left(Main.PoNo,Len(Main.PoNo)-1) As "PoNo",Left(Main.PoDt,Len(Main.PoDt)-1) As "PoDt"
From
    (
        Select distinct ST2.Ibill_no, 
            (
                Select ST1.PoNo + ',' AS [text()]
                From dbo.items_sold ST1
                Where ST1.Ibill_no = ST2.Ibill_no
                ORDER BY ST1.Ibill_no
                For XML PATH ('')
            ) [PoNo],
            (
                Select cast(ST1.podate as char(11)) + ',' AS [text()]
                From dbo.items_sold ST1
                Where ST1.Ibill_no = ST2.Ibill_no
                ORDER BY ST1.Ibill_no
                For XML PATH ('')
            ) [PoDt]
        From dbo.items_sold ST2
    ) [Main]
END

日期是日期,没有别的!由于字段类型 [ ^ ]和几个设置 [ ^ ]日期格式可能不同。



要使用自定义格式显示日期,请检查:

日期和时间格式 [ ^ ]

CAST和CONVERT(Transact-SQL) [ ^ ]

FORMAT(Transact-SQL) [ ^ ]
Date is date and nothing else! Due to the type of field[^] and several settings[^] date format may differ.

To display date using custom format, please check this:
Date and Time Formats[^]
CAST and CONVERT (Transact-SQL)[^]
FORMAT (Transact-SQL)[^]


您似乎正在尝试在数据库服务器上格式化日期。我建议不要这样做。而是将日期值作为日期提取到客户端,并在那里处理格式。通过这种方式,您可以轻松确保使用正确的格式。



整体SQL用于数据获取和操作,并且它不适合格式化。其他语言和工具的目标是显示数据。
It seems that you're trying to format date on the database server. I would advice not to do this. Instead fetch the date value to the client side as date and handle formatting over there. This way you can easily ensure that correct format is used.

In overall SQL is meant for data fetching and manipulation and it's a poor candidate for formatting. Other languages and tools are targeted for displaying data.