Solved

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

Posted on 2004-04-30
2
1,424 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

Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Database-Scoped Permissions 2 41
Database Owner 3 45
MySQL - Adding an incremented value to a duplicate string 30 51
[Unsupported] SQL Update in CRM 2011 Database 19 64
Creating and Managing Databases with phpMyAdmin in cPanel.
This article shows the steps required to install WordPress on Azure. Web Apps, Mobile Apps, API Apps, or Functions, in Azure all these run in an App Service plan. WordPress is no exception and requires an App Service Plan and Database to install
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…

732 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