Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Converting smalldatetime datatype to varchar datatype

Tags:

sql

sql-server

How to convert smalldatetime to varchar? I've tried everything from http://msdn.microsoft.com/en-us/library/ms187928.aspx, but it didn't work.

I want to convert smalldatetime into varchar, because I want to use it in select like this:

select 'Some text'+@Date

thanks in advance

like image 546
Eric Klaus Avatar asked Feb 13 '23 08:02

Eric Klaus


1 Answers

'121' is the format of the date in this case 'yyyy-mm-dd hh:mi:ss.mmm(24h)', char(16) is the number of characters you wish to include, first 16 in this case.

select 'Some text'+convert(char(16), @date, 121)

Cast and Convert

like image 69
t-clausen.dk Avatar answered Feb 16 '23 09:02

t-clausen.dk