Reputation: 2252
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?
Upvotes: 3
Views: 5649
Reputation: 1164
Please try this:
SELECT
VisitID AS Value,
CONVERT(VARCHAR, VisitID, 20) + '-' + ISNULL(CONVERT(VARCHAR, VisitDate, 20), '') AS Text
FROM Visit
Upvotes: 2
Reputation: 18569
Use CONVERT and supply third parameter for date and time styles.
Try this:
select VisitID as Value, Convert(nvarchar(50),VisitID)+' - '+Convert(nvarchar(50),VisitDate, 101) as Text
from Visit
Upvotes: 2
Reputation: 131
SELECT
visitid [Value]
,(CAST(VisitID AS VARCHAR) + '-' _ CAST(VisitDate AS VARCHAR)) [Text]
FROM Visit
Upvotes: 0