[Solved] Concatenate 4 fields into a 13 digit number

Creating tables and queries
Post Reply
hitch_hiker
Posts: 8
Joined: Wed Jul 15, 2015 1:55 pm

[Solved] Concatenate 4 fields into a 13 digit number

Post by hitch_hiker »

I want to have 4 fields "category" ( default 02 ), "product_number" (nnnnn),"price" ($$$$$) & "cksum" (#) and I need to concatenate into a 13 digit number (02nnnnn$$$$$#), It would be easier for me to have the separate fields for data entry, but I will need to have the entire number for use later. I'm expecting the resultant number to then populate another field e.g. "barcode". I did a a few searches but nothing seemed to come close, Any suggestions?
Last edited by RoryOF on Wed Aug 26, 2015 5:08 am, edited 2 times in total.
open office 4 on windows 8.1
FJCC
Moderator
Posts: 9280
Joined: Sat Nov 08, 2008 8:08 pm
Location: Colorado, USA

Re: how to concatenate 4 fields into a 13 digit number

Post by FJCC »

Something like

Code: Select all

SELECT "category" || "product_number" || "price" || "chksum" AS "barcode" FROM "MyTable"
should work. It is best not to store such results in the table because if you later update one of the column values, the concatenated column will not automatically update. You can always construct the concatenation in a query as needed.
OpenOffice 4.1 on Windows 10 and Linux Mint
If your question is answered, please go to your first post, select the Edit button, and add [Solved] to the beginning of the title.
hitch_hiker
Posts: 8
Joined: Wed Jul 15, 2015 1:55 pm

Re: how to concatenate 4 fields into a 13 digit number

Post by hitch_hiker »

Thanks FJCC, next question, I have only just started, and currently on the vertical section of the learning curve, can you suggest what I need to search to find out where and how to use this code, Not wanting you to build it for me, just have no idea on the processes I need. Are the lines between the field names 'pipe' (Shift \ ) ?
open office 4 on windows 8.1
FJCC
Moderator
Posts: 9280
Joined: Sat Nov 08, 2008 8:08 pm
Location: Colorado, USA

Re: how to concatenate 4 fields into a 13 digit number

Post by FJCC »

It is hard to know what to suggest since I don't know what you are trying to accomplish. For general query writing, there are many SQL tutorials on line. I don't have a particular one to recommend as I'm old enough to have learned from a book. Just search the web on the terms SQL Tutorial and find one you like. If you can explain more about your goal, we may be able to suggest some resources.
Yes, the vertical bars are pipes.
OpenOffice 4.1 on Windows 10 and Linux Mint
If your question is answered, please go to your first post, select the Edit button, and add [Solved] to the beginning of the title.
hitch_hiker
Posts: 8
Joined: Wed Jul 15, 2015 1:55 pm

Re: [solved]how to concatenate 4 fields into a 13 digit numb

Post by hitch_hiker »

Thanks heaps FJCC, I'm (probably re-inventing the wheel) creating an invoicing system, and more, It did not click that I need to do a query, from here I can research it, I'm guessing I can display the result of a query in a form.
open office 4 on windows 8.1
Post Reply