Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

add a prefix to results

Status
Not open for further replies.

Cpreston

MIS
Mar 4, 2015
972
GB
Hi

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

11003334455
11003456222

and so on

Thanks
 
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):
Code:
SELECT [b]'[/b]1100[b]'[/b] + OH.OrderID AS [CALL.ID]...
[code]

Borislav Borissov
VFP9 SP2, SQL Server
 
Hi

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.

SELECT RIGHT('1100' +CAST(OH.OrderID AS VARCHAR),12)
 
This is a classic example of faq68-6659.

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.

Skip,
[sub]
[glasses]Just traded in my OLD subtlety...
for a NUance![tongue][/sub]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top