3

I try to concatenate id and date to populate in dropdown.

select VisitID as Value,  Convert(nvarchar(50),VisitID)+' - '+Convert(nvarchar(50),VisitDate) as Text 
from Visit

above query work for me to concatenate but the result is in the form of '21 - Feb 13 2013 12:00AM'

i want the result should be in form of '21 - 02/13/2012'

what I need to do?

4

3 回答 3

2

使用CONVERT并为日期和时间样式提供第三个参数。

尝试这个:

select VisitID as Value, Convert(nvarchar(50),VisitID)+' - '+Convert(nvarchar(50),VisitDate, 101) as Text 
from Visit
于 2013-03-05T05:20:11.063 回答
2

请试试这个:

SELECT 
 VisitID AS Value, 
 CONVERT(VARCHAR, VisitID, 20) + '-' + ISNULL(CONVERT(VARCHAR, VisitDate, 20), '') AS Text 
FROM Visit
于 2013-03-05T05:21:49.500 回答
0
SELECT
visitid [Value]
,(CAST(VisitID AS VARCHAR) + '-' _ CAST(VisitDate AS VARCHAR)) [Text]
FROM Visit
于 2013-03-05T05:15:50.407 回答