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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Creating New Feild By Concatonating a Character and Numeric Filed

Status
Not open for further replies.

edrossi

Programmer
Jan 24, 2002
42
US
Is there an easy way to concatonate the following:

R0 - Character field
07 - Numeric field

result needed: R007 - Character field

Thanks is advance for the help.....
 
Sure. One way is to use TRANSFORM(). e.g.
cX = "R0"
nX = 7
cY = cX + Transform(nX, "@L 99")

Rick
 
It all depends on what you ultimately want... if you are just massaging data, then do this:

ALTER TABLE ADD COLUMN newField C(40)
REPLACE ALL newField WITH Left(ChrFld,2)+alltrim(str(NumFld))

However, this "newField" will NOT be updated when the values in ChrFld and NumFld are changed.

What is it you want to do with the "newField"? Will all future records that are added only fill in newField?
 
HI Edrossi,

ResultNeeded = ALLTRIM(charField)+ALLTRIM(STR(NumField))

Hope this helps you :) ramani :)
(Subramanian.G),FoxAcc, ramani_g@yahoo.com
 
Well actually that will not work.

using something like this :

cx = "RO"
nx = 7

adding these together like

cx + alltrim(str(nx)) will give you "RO7"

You stated you needed to get the result "RO07"

you will need to pad the numeric field with a zero "0" if the length of it is not 2 characters.

if len(alltrim(str(nx)) = 1
mresults = cx + "0" + alltrim(str(nx))
else
mresults = cx + alltrim(str(nx))
endif

that should give you the desired result.
 
TRY THIS
CHARACTER+PADL(ALLTRIM(STR(NUMERICVALUE,2,0)),2,"0")
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top