473,394 Members | 1,770 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,394 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 1926
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,556 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,556 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,556 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 =...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.