Matt
Matt

Reputation: 4190

SQL string '00000' displaying as '0'

Can someone explain why

CASE 
   WHEN MARK = 'Y' 
     THEN LEFT('00000', 5-LEN(DATEDIFF(MINUTE, START, FINISH))) + DATEDIFF(MINUTE, START, FINISH) 
     ELSE '00000' 
END AS [Time]

Is displaying as a single 0 instead of 00000 when Mark <> 'Y', and displaying 35 instead of 00035 (as an example)

Upvotes: 0

Views: 566

Answers (2)

Sreenath
Sreenath

Reputation: 111

My understanding is that you are using MSSQL server. If, yes then the default datatype for any variable or nullable column is INT

Upvotes: 0

TheNorthWes
TheNorthWes

Reputation: 2739

I would guess SQL is converting it to an integer.

Code like this select cast('00000' as varchar) returns as you wish (00000, 00035) but select cast('00000' as int) returns your results (0, 35 etc)

Upvotes: 3

Related Questions