473,287 Members | 1,880 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,287 software developers and data experts.

Multiple If statements

I have a table that I need to use multiple if statements to update the description of a field and then create a new column for these results
Table: MyPlants

if field1= "Flowering Plants" then
field1= "Garden 1"
if field2= "Herbs" then
field2- "Garden 2"

I have multiple ifs like 30

Then I have a create another column for the results like

New Column (Updated List) in MyPlants Table

Updated List
Garden 1
Garden 2
May 28 '16 #1

✓ answered by NeoPa

In this case it looks like some form of lookup is required. Thirty-odd Ifs is very cumbersome indeed. Not a fun way to write code.

For handling such things in VBA (Which I don't recommend but I'm covering anyway for info.) you could consider the Select Case construct or the Switch() function if you need a single returned value based on many different checks.

5 1921
PhilOfWalton
1,430 Expert 1GB
It sounds as if your database is not normalised.

Could you please let us have your MyPlants table structure and some sample data and where you want this Updated List to appear.

Phil
May 28 '16 #2
NeoPa
32,554 Expert Mod 16PB
This approach doesn't sound very well thought out, or maybe it's just poorly explained.

Anyway, overwriting your original data is very rarely a good approach. Without more information (Even if your question is accurate it's very sparse on logic so we're working blind to a large extent.) it's hard to know for sure, but I'd consider a table structure that allows for data transformation (probably not in place) based on some form of lookup table.
May 28 '16 #3
NeoPa
32,554 Expert Mod 16PB
In this case it looks like some form of lookup is required. Thirty-odd Ifs is very cumbersome indeed. Not a fun way to write code.

For handling such things in VBA (Which I don't recommend but I'm covering anyway for info.) you could consider the Select Case construct or the Switch() function if you need a single returned value based on many different checks.
May 28 '16 #4
PhilOfWalton
1,430 Expert 1GB
Am waiting for more info, but it's my guess that he needs a a table of Plants, a table of Locations and probably a joinPlantLocation table

Phil
May 28 '16 #5
NeoPa
32,554 Expert Mod 16PB
Indeed. It's hard to offer advice when the question hasn't been formulated properly. So much guesswork, and one thing wrong can make all the advice inappropriate :-(
May 30 '16 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Shmuel | last post by:
Is it possible to query multiple statements at once? Like: $query = "set @p := 1; select @p + 1"; $results = mysql_query($query); I'm thinking of PHP4. There is in mysqli the prepare...
2
by: Richard Adams | last post by:
Is it possible to execute more than one statement in SQL via MDAC ODBC? I have a fairly complex select I wanted to create a view with, but trying to send it all as one string with terminators ';'...
1
by: Erik Haugen | last post by:
This item in the C++ faq: http://www.parashift.com/c++-faq-lite/misc-technical-issues.html#faq-38.5 discusses macros with multiple statements. The problem is that a macro such as #define...
4
by: DG | last post by:
Hi, Can anyone advise how to execute multiple statements in a single query batch. For example- update customers set customer_name = 'Smith' where customer_name = 'Smyth'; select * from...
2
by: Nabil | last post by:
I am new to DB2 and here is my situation. I have 2 temp tables where I am trying to insert data (from 2 select statements) DECLARE v_t1 VARCHAR(50); DECLARE v_t1 VARCHAR(50); DECLARE stmt1...
2
by: Annie D via AccessMonster.com | last post by:
Hi, Is it possible to use multiple statements in SQL?? (I’ve never used it before) : I have one query that i'm working with, The statements I want to use are as below, they all work...
1
by: arthy | last post by:
Hi, Is it possible to execute multiple statements on to the database using a single dbconnection object.what is the drawback in using .If not possible ,then how can the execution of multiple...
7
by: paladin.rithe | last post by:
I have 2 statements that I'd like to string together in a query, but according to everything I'm seeing, it's not possible. What I'm doing is an insert of a row, where the primary key is an auto...
6
by: jodleren | last post by:
another topic though related to the previous post. How do IF behave in php? Say, if( $goahead && copy($somefile1, $somefile2) ) echo "hello world"; What if $goahead is false, will the if...
0
by: harsha318 | last post by:
Hi I need to have a single query and which can have multiple statements For eg: string str = string.Empty; str = "select * from Customers;Select * from Orders"; iDB2Connection iDB2con =...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.