473,372 Members | 1,212 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,372 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 7581
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...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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: 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...

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.