Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

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

Posted on 2004-04-30
2
Medium Priority
?
1,440 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
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 400 total points
ID: 10962672

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

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

In this blog post, we’ll look at how ClickHouse performs in a general analytical workload using the star schema benchmark test.
What we learned in Webroot's webinar on multi-vector protection.
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…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Suggested Courses

810 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