473,411 Members | 2,289 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,411 software developers and data experts.

Updating multiple columns with several conditions

Hi,

I have a table which has columns name, date1, date2.
Through 'Or' condition, i can update name but to update date1 and date2 I have another condition. ID1 matches, date1 will be updated and date2 on ID2.
How to set these columns in a single query?


Thanks,
Prat
Jun 3 '08 #1
2 7587
deepuv04
227 Expert 100+
Hi,

I have a table which has columns name, date1, date2.
Through 'Or' condition, i can update name but to update date1 and date2 I have another condition. ID1 matches, date1 will be updated and date2 on ID2.
How to set these columns in a single query?


Thanks,
Prat
hi,
try something like
Expand|Select|Wrap|Line Numbers
  1. UPDATE Table_Name
  2. SET Name = @New_Name,
  3.     Date1 = CASE @Value WHEN ID1 THEN @New_Date
  4.             ELSE Date1 END,
  5.     Date2 = CASE @Value WHEN ID2 THEN @New_Date
  6.             ELSE Date2 END
  7. WHERE Your_Condition
  8.  
thanks
Jun 3 '08 #2
Thanks a lot! It works



hi,
try something like
Expand|Select|Wrap|Line Numbers
  1. UPDATE Table_Name
  2. SET Name = @New_Name,
  3.     Date1 = CASE @Value WHEN ID1 THEN @New_Date
  4.             ELSE Date1 END,
  5.     Date2 = CASE @Value WHEN ID2 THEN @New_Date
  6.             ELSE Date2 END
  7. WHERE Your_Condition
  8.  
thanks
Jun 3 '08 #3

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

Similar topics

6
by: Dennis | last post by:
In CSS3 it looks like we'll have multiple column flowing of text (newspaper style) in which the number of columns can be determined automatically given the available horizontal space....
7
by: Billy Jacobs | last post by:
I am using a datagrid to display some data. I need to create 2 header rows for this grid with columns of varying spans. In html it would be the following. <Table> <tr> <td colspan=8>Official...
0
by: David Londeck | last post by:
I am using Visual Basic 2003 and I have written a notepad like application using the RichTextBox control. I am having trouble trying to emulate Microsoft Words text block copy/paste feature. In...
3
by: Jane | last post by:
Hi, If anyone could help me with this, I greatly appreciate it. I would like to know how I can display data from a db in multiple columns rather than have it displayed in 1 column per recordset....
1
by: davidevan | last post by:
I'm trying to update a single field in a table according to the an age category as a condition. The meat of the code that executes looks like this (I created a record set, and loop through it...
2
by: eighthman11 | last post by:
Hi everyone. I am updating a table with aggregate results for multiple columns. Below is an example of how I approached this. It works fine but is pretty slow. Anyone have an idea how to...
2
by: ray well | last post by:
i need to display 2 columns of data in a list box. how would i set this up IN CODE. say my table is tblNames, and i have 2 fields, FirstName, LastName, and want the data to show up in 2...
3
by: Leif Neland | last post by:
This is not supported in MSsql. update T1 set (theUpdatedValue, theOtherValue) = (select theTop, theValue from T2 where T2.theKey = T1.theID) Is there a workaround? Other than doing it in a...
3
by: Will | last post by:
Can someone help with code to delete multiple columns from an excel spreadsheet? I know which columns I need to delete. The code below will delete a single column but I'm not sure how to delete...
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
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.