We'd like to remind Forumites to please avoid political debate on the Forum... Read More »
Anyone good with SQL?
Comments
-
flaneurs_lobster said:Old programmer in me is shouting "get the input data validation tightened up".
Makes this type of problem unnecessarily hard if the conditional tests can have any old rubbish thrown at them.
For info, I take the CSV, convert it to xlxs format and run a macro that converts the format of the fields to suit the target database table, then I append the data to that table. Then I run the SQL in the database that allocates a 'Type' number to the various spend categories. Then the database forms are use to select/display the spend/totals by type.
I suppose I could run a macro on the CSV or XLXS (or add to my existing macro) that would change all company names to upper or lower case and that would avoid me having to change my rather large SQL by adding 'upper' in lots of places. (Edit: I'd still have to make lots of changes actually.) Perhaps that's a question for another thread. Still wouldn't get rid of the extra characters like Fred's.
Anyway It's been good to see the solutions quoted here.0 -
Probably a whole new project you may not even wish to tackle, but you could bypass using Excel altogether and just develop a routine in Libre office to import the data into the database.
I have no idea what capabilities Libre office has, but it could be worth a new thread on here if you wished to explore it...I’m a Forum Ambassador and I support the Forum Team on the In My Home MoneySaving, Energy and Techie Stuff boards. If you need any help on these boards, do let me know. Please note that Ambassadors are not moderators. Any posts you spot in breach of the Forum Rules should be reported via the report button, or by emailing forumteam@moneysavingexpert.com.
All views are my own and not the official line of MoneySavingExpert.
1 -
Excel can open .csv files without converting. and a macro can be written to just ingest the data straight from an external file (if you know the file format, which presumably you do).
From a data perspective, it would make more sense to standardise the data on load rather than at point of use -1 -
JohnB47 said:flaneurs_lobster said:Old programmer in me is shouting "get the input data validation tightened up".
Makes this type of problem unnecessarily hard if the conditional tests can have any old rubbish thrown at them.1 -
Thanks for the ideas. I'll look into those.0
-
Depending on size/scope of system, you'd generally not put the literal text of the supplier name in the Spend table, but instead had a supplier table with unique numeric code for each supplier, along with the standard name text. Possibly also a 'parent' code field so you can build a hierarchy of suppliers. The supplier's code number would go into the Spend table.
Of course your input data processing will need to a process to add new suppliers and correct variations on the name of existing suppliers to link to their code number.1 -
Vitor said:Depending on size/scope of system, you'd generally not put the literal text of the supplier name in the Spend table, but instead had a supplier table with unique numeric code for each supplier, along with the standard name text. Possibly also a 'parent' code field so you can build a hierarchy of suppliers. The supplier's code number would go into the Spend table.
Of course your input data processing will need to a process to add new suppliers and correct variations on the name of existing suppliers to link to their code number.0 -
JohnB47 said:Thanks for the quick replies folks. Obviously I'll play around with those suggestions but I need to check my understanding.
A couple of you have referred to 'changing' the case and "Another vote to change case using upper or lower." I don't actually want to change the entries in the "Description" field. I want the SQL to inspect and find those records where that field has, say Fred, or FRED or fred in them and then carry out a procedure accordingly.
Anyway, are you saying that this code would work (given my simple example):UPDATE "tblSpend"
SET "Type" = '4'
WHERE (upper("Description") Like upper('%Freds Groceries%'))
I can't quite see why that would do what I want. But then what do I know! Thanks again.
UPDATE "tblSpend"
SET "Type" = '4'
WHERE ("Description" iLike '%Freds Groceries%')
0 -
Shimrod said:JohnB47 said:Thanks for the quick replies folks. Obviously I'll play around with those suggestions but I need to check my understanding.
A couple of you have referred to 'changing' the case and "Another vote to change case using upper or lower." I don't actually want to change the entries in the "Description" field. I want the SQL to inspect and find those records where that field has, say Fred, or FRED or fred in them and then carry out a procedure accordingly.
Anyway, are you saying that this code would work (given my simple example):UPDATE "tblSpend"
SET "Type" = '4'
WHERE (upper("Description") Like upper('%Freds Groceries%'))
I can't quite see why that would do what I want. But then what do I know! Thanks again.
UPDATE "tblSpend"
SET "Type" = '4'
WHERE ("Description" iLike '%Freds Groceries%')
0 -
Vitor said:Depending on size/scope of system, you'd generally not put the literal text of the supplier name in the Spend table, but instead had a supplier table with unique numeric code for each supplier, along with the standard name text. Possibly also a 'parent' code field so you can build a hierarchy of suppliers. The supplier's code number would go into the Spend table.
Of course your input data processing will need to a process to add new suppliers and correct variations on the name of existing suppliers to link to their code number.
Or "use third normal form in your database design".
Proud member of the wokerati, though I don't eat tofu.Home is where my books are.Solar PV 5.2kWp system, SE facing, >1% shading, installed March 2019.Mortgage free July 20231
Confirm your email address to Create Threads and Reply

Categories
- All Categories
- 351K Banking & Borrowing
- 253.1K Reduce Debt & Boost Income
- 453.6K Spending & Discounts
- 244.1K Work, Benefits & Business
- 599K Mortgages, Homes & Bills
- 177K Life & Family
- 257.4K Travel & Transport
- 1.5M Hobbies & Leisure
- 16.1K Discuss & Feedback
- 37.6K Read-Only Boards