Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here


add a prefix to results

add a prefix to results

add a prefix to results


I want to add 4 digits to the answers from a query. I am using 2008R2 so cannot use concat. I have tried using the + but cannot get it to work, could someone point me in the right direction, I am sure it is simple but just cant seem to get it right. Thanks

SELECT 1100 + '' + OH.OrderID AS [CALL.ID], REPLACE(REPLACE(OH2.SpecialInstructions, CHAR(13), ' '), CHAR(10), '') AS [CALL.TEXT01]
FROM dbo.DeliveryBookingLine

so the results would be something like


and so on


RE: add a prefix to results

When you want to concatenate strings ALL variables you use should be strings.
You can not concatenate integers and strings (you should convert integers to strings first):
SELECT '1100' + OH.OrderID AS [CALL.ID]...

Borislav Borissov
VFP9 SP2, SQL Server

RE: add a prefix to results


Thanks for the reply.

SELECT '1100' + OH.OrderID AS [CALL.ID]

this just brings back 3349729 where I was expecting 1100334972

I have used the below and this works and gives the expected result.


RE: add a prefix to results

This is a classic example of FAQ68-6659: When is a NUMBER not a NUMBER?.

An invoice ID, comprised of all numeric DIGITS, would never be used in a mathematical calculation, except to calculatulate the next ID in the series, which can be done mathematically with any alpha-numeric ID.

But you'd NEVER take the log of your ID or raise your ID to the power of x. So IMNSHO, an ID ought to be stored, declared and used as a STRING.


glassesJust traded in my OLD subtlety...
for a NUance!tongue

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close