Solved

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

Posted on 2004-04-30
2
1,421 Views
Last Modified: 2007-12-19
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?
0
Comment
Question by:LloydMc
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 7

Expert Comment

by:Lori99
ID: 10961703
Try this:

convert(varchar(10),cast(distance as int)) + ' miles' as distance
0
 
LVL 7

Accepted Solution

by:
mikkilineni earned 100 total points
ID: 10962672

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

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

CCModeler offers a way to enter basic information like entities, attributes and relationships and export them as yEd or erviz diagram. It also can import existing Access or SQL Server tables with relationships.
Creating and Managing Databases with phpMyAdmin in cPanel.
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

735 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question