FastReport / Report Query Help - How do i convert a integer value into a string ?

I am using FastReport to create my reports right now, and i have an issue.
I have an one data attribute named "ProductMaster.ITEMBUYINGPRICE".

The output of this data is a 6 digit value showing the cost price. Let us say, for example its 205,450 .

However since this report needs to be printed . I need to encrypt the costs into an alphabetical value so only certain staffs who know the encryption would be able to know the cost . Therefore i need the report to automatically convert the data stored in ITEMBUYINGPRICE into a string value

My formula is as follows :
V = 1
G = 2
O = 3
B = 4
I = 5
N = 6
D = 7
R = 8
A = 9
M = 0

Therefore the cost above would read as "GMIBIM"

Could you guide me as to how/what function i should use  to code this into the report?

Amrit SamtaniAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

I looked through the user's manual on Fast Reports.  I don't see a way to do what you want.

There was mention of a scripting tool, Fast Scripts, that might be able to do what you want.

PortletPaulEE Topic AdvisorCommented:
what is the dbms type & version you are using?
Ryan ChongBusiness Systems Analyst , ex-Senior Application EngineerCommented:
what's the database you're using? perhaps you can have a custom function to do the conversion of field: ProductMaster.ITEMBUYINGPRICE before passing the query to fast report? does it make sense to you?
SolarWinds® VoIP and Network Quality Manager(VNQM)

WAN and VoIP monitoring tools that can help with troubleshooting via an intuitive web interface. Review quality of service data, including jitter, latency, packet loss, and MOS. Troubleshoot call performance and correlate call issues with WAN performance for Cisco and Avaya calls

Sinisa VukSoftware architectCommented:
Custom function in DB is a very good option but can be done in Delphi too. There is an event OnGetValue (FastReport component) - create it. In report file put custom parameter instead of field name (lets say: [MyEncodedPrice]). Report engine will call your event method. There should be:
if ParName='MyEncodedPrice]' then
  ParValue := Rpt.DataSet.FieldByName('ITEMBUYINGPRICE').AsString;
  ParValue := StringReplace(ParValue, ',','',[rfReplaceAll]); //remove comma
  ParValue := StringReplace(ParValue, '1','V',[rfReplaceAll]); //replace 1
  ParValue := StringReplace(ParValue, '2','G',[rfReplaceAll]);
  ParValue := StringReplace(ParValue, '0','M',[rfReplaceAll]); //replace 0

Open in new window

... and this is it.
Geert GOracle dbaCommented:
create a function on the database and then use that
the easy thing is only your sql code requires some change

for oracle it could be like this

select price, pricecrypto(price) encrypted_price from table

Open in new window

create or replace function pricecrypto (num in number) return varchar2
  v_num varchar2(100);
  v_ch varchar2(20);
  v_ch :=  'MVGOBINDRA'; -- from 0 to 9
  v_num := to_char(num);
  for i in 0 .. 9 loop
    v_num := replace(v_num, i, substr(v_ch, i+1, 1));
  end loop;
  return v_num;

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Geert GOracle dbaCommented:
delphi code is similar

a little bit compacter with a for than sinisa's code
function PriceCrypto(price: string): string;
const ch = 'MVGOBINDRA';
var I: Integer;
  Result := Price;
  for I := 0 to 9 do
    Result := StringReplace(Result, IntToStr(I), Copy(ch, I+1, 1), [rfReplaceAll]);

Open in new window

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.