How to concatenate literal expression with other fields in T-SQL

I'm trying to cancatenate the following: a float field truncated to an int, combined with the literal string ' miles' to form the aliased varchar field distance, but getting a casting exception

t-sql line:
CAST(CAST(z.distance AS INT) +  ' miles' AS varchar(9))AS distance

exception:
[Microsoft][ODBC SQL Server Driver][SQL Server]Syntax error converting the varchar value 'miles' to a column of data type int.

Any ideas as to what I'm doing wrong?
LloydMcAsked:
Who is Participating?
 
mikkilineniConnect With a Mentor Commented:

This should work
CAST(CAST(z.distance AS INT) AS varchar(9) +  ' miles' AS distance
0
 
Lori99Commented:
Try this:

convert(varchar(10),cast(distance as int)) + ' miles' as distance
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.