Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

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

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

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

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.
Lotus Notes has been used since a very long time as an e-mail client and is very popular because of it's unmatched security. In this article we are going to learn about  RRV Bucket corruption and understand various methods to Fix "RRV Bucket Corrupt…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses

636 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