Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Concatenate in sql server query

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?

like image 535
Nomi Ali Avatar asked Jan 19 '26 11:01

Nomi Ali


1 Answers

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
like image 157
Iswanto San Avatar answered Jan 21 '26 02:01

Iswanto San



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!