473,399 Members | 4,192 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,399 software developers and data experts.

UPDATE a variable to different categories by a single step?

Hello,

I am trying to update variable 'Type' (which is a pre-defined variable
without any value in it). Is there a way to combine Step1 to Step3 into
one single Update? I tried the query at the bottom but it didn't work.
Thanks a lot!

--STEP1:
Update TABLE1
set type = case
when name like '%Airline%' then 'Airlines'
else 'Others'
end

--STEP2:
update TABLE1
set type = case
when name like '%Brokerage%' then 'Brokerage'
else 'Others'
end
where type = 'Others'

--STEP3:
update TABLE1
set type = case
when name like '%card%' then 'Credit Card'
else 'Others'
end
where type = 'Others'

--Failed query:
Update TABLE1
set type = case
when name like '%Airline%' then 'Airlines'
else when name like '%Brokerage%' then 'Brokerage'
else when name like '%card%' then 'Credit Card'
else 'Others'
end

Jul 23 '05 #1
6 1157
On 10 Feb 2005 10:02:35 -0800, ro******@gmail.com wrote:
--Failed query:
Update TABLE1
set type = case
when name like '%Airline%' then 'Airlines'
else when name like '%Brokerage%' then 'Brokerage'
else when name like '%card%' then 'Credit Card'
else 'Others'
end


Hi rong.guo,

You were almost there - you only need to remove all but one of the ELSE:

Update TABLE1
set type = case
when name like '%Airline%' then 'Airlines'
when name like '%Brokerage%' then 'Brokerage'
when name like '%card%' then 'Credit Card'
else 'Others'
end

Best, Hugo
--

(Remove _NO_ and _SPAM_ to get my e-mail address)
Jul 23 '05 #2
Thanks Hugo!

But will this give me mutually exclusive groups? For example, if i have
a record 'Airline Card', it will be put into "Airlines' group first,
and then re-tag as "Credit Card' later, but I want it to stay in
"Airlines" group. Thanks.

Jul 23 '05 #3
On 10 Feb 2005 10:17:50 -0800, ro******@gmail.com wrote:
Thanks Hugo!

But will this give me mutually exclusive groups? For example, if i have
a record 'Airline Card', it will be put into "Airlines' group first,
and then re-tag as "Credit Card' later, but I want it to stay in
"Airlines" group. Thanks.


Hi rong.guo,

In the evaluation of a CASE, the first WHEN that evaluates as true will be
used and the accompanying THEN will be the result; the remaning WHEN
clauses will never even be evaluated.

So if you have
when name like '%Airline%' then 'Airlines'
before
when name like '%card%' then 'Credit Card'
then the name 'Airline Card' would result in type 'Airlines'.

Best, Hugo
--

(Remove _NO_ and _SPAM_ to get my e-mail address)
Jul 23 '05 #4
Thanks Hugo, so the order of the WHEN clauses here does matter,
correct?

Jul 23 '05 #5
On 10 Feb 2005 10:36:51 -0800, ro******@gmail.com wrote:
Thanks Hugo, so the order of the WHEN clauses here does matter,
correct?


Hi rong.guo,

Yes, that is correct.

Best, Hugo
--

(Remove _NO_ and _SPAM_ to get my e-mail address)
Jul 23 '05 #6
Thanks again!

Jul 23 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Brian | last post by:
Greetings, I'm working on a project that involved that has need of a categorization system. Logically speaking, the system will have elements, these elements will belong to at least a single...
6
by: BigDadyWeaver | last post by:
I am using the following code in asp to define a unique and unpredictable record ID in Access. <% 'GENERATE UNIQUE ID Function genguid() Dim Guid guid =...
3
by: Justin | last post by:
I have created a dataset with two tables and an insert command, I need to be able to retreive the Key Identity after inserting into table "A" for use in table "B". Should I use ExecuteScalar()...
11
by: Siv | last post by:
Hi, I seem to be having a problem with a DataAdapter against an Access database. My app deletes 3 records runs a da.update(dt) where dt is a data.Datatable. I then proceed to update a list to...
5
by: Earl | last post by:
I want to fire a database update off of a single change to a single cell in the datagrid. This apparently cannot be done using keypress, keyup, keydown, etc. I've read George Shepard's FAQ and...
5
by: Louis LeBlanc | last post by:
Hey folks. I'm new to the list, and not quite what you'd call a DB Guru, so please be patient with me. I'm afraid the lead up here is a bit verbose . . . I am working on an application that...
7
by: Jon Maz | last post by:
Hi, I have a MySql problem I hope someone can help me with. I'm trying to run an update on a linking table, the update is running into a Primary Key constraint violation, and in my workaround...
19
by: Steve | last post by:
ASP error number 13 - Type mismatch with SELECT...FOR UPDATE statement I got ASP error number 13 when I use the SELECT...FOR UPDATE statement as below. However, if I use SELECT statement without...
6
by: berndh | last post by:
Hi, I have a need to update all price fields in an SQL database. The new prices are in an excel spreadsheet (c:\db\update.xls). Unfortunately the structure of the Excel file is not the same as...
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: 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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.