Author |
Topic |
soori457
Yak Posting Veteran
85 Posts |
Posted - 2008-01-28 : 02:51:05
|
HaiI want to update mutiple rows using single statement. GenderMFNow I want to update M as Male and F as Female in Gender Table using single Sql Statement.Can anyone help me pleaseThanks in Advance...Suresh Kumar |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-01-28 : 03:00:08
|
UPDATE TableSET Gender =CASE WHEN Gender ='M' THEN 'Male' WHEN Gender ='F' THEN 'Female' END |
 |
|
soori457
Yak Posting Veteran
85 Posts |
Posted - 2008-01-28 : 03:10:17
|
The problem with this is, its updating only one row.I want to update both the rows at a time only.Suresh Kumar |
 |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-01-28 : 03:14:59
|
quote: Originally posted by soori457 The problem with this is, its updating only one row.I want to update both the rows at a time only.Suresh Kumar
One row? can you post sample data of your table & expected o/p? |
 |
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2008-01-28 : 03:35:06
|
You maybe want to reset the ROWCOUNT variable?SET ROWCOUNT 0UPDATE TableSET Gender = CASE WHEN Gender ='M' THEN 'Male'WHEN Gender ='F' THEN 'Female'ELSE 'Unknown'END E 12°55'05.25"N 56°04'39.16" |
 |
|
soori457
Yak Posting Veteran
85 Posts |
Posted - 2008-01-28 : 04:07:31
|
THnks for ur repliesGender(Coloumn Name)M(data)F(data)With single sql statement, I want to update M as Male and F as FemaleThis is the required o/p I wantGenderMaleFemaleSuresh Kumar |
 |
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2008-01-28 : 04:11:17
|
And you have got them too. E 12°55'05.25"N 56°04'39.16" |
 |
|
soori457
Yak Posting Veteran
85 Posts |
Posted - 2008-01-28 : 04:57:31
|
UPDATE TableSET Gender = CASE WHEN Gender ='M' THEN 'Male'WHEN Gender ='F' THEN 'Female'ELSE 'Unknown'ENDwith this query, I'm updating only one rowBut I want both rows should be updated simlutaneously with single sql statementSuresh Kumar |
 |
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2008-01-28 : 05:05:36
|
You are updating complete table!Try the query and you will find out.You need to learn set-based thinking... E 12°55'05.25"N 56°04'39.16" |
 |
|
soori457
Yak Posting Veteran
85 Posts |
Posted - 2008-01-28 : 05:51:16
|
Yah, I have tried it, But I'm not getting, only one row is updating and the other one is deleted. When I run the above query, I'm getting the o/p asGenderMaleFirst of all, tell me, is it possible to update mutliple rows of same column simultaneously.Suresh Kumar |
 |
|
soori457
Yak Posting Veteran
85 Posts |
Posted - 2008-01-28 : 06:10:57
|
Yah, I have tried it, But I'm not getting, only one row is updating and the other one is deleted. When I run the above query, I'm getting the o/p asGenderMaleFirst of all, tell me, is it possible to update mutliple rows of same column simultaneously.Suresh Kumar |
 |
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2008-01-28 : 06:39:57
|
quote: Originally posted by soori457 Yah, I have tried it, But I'm not getting, only one row is updating and the other one is deleted. When I run the above query, I'm getting the o/p asGenderMaleFirst of all, tell me, is it possible to update mutliple rows of same column simultaneously.
YES IT IS POSSIBLE!And there is NO WAY records can be deleted from ANY of the statements posted above. E 12°55'05.25"N 56°04'39.16" |
 |
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2008-01-28 : 08:42:54
|
What is the size Gender column?See if select worksSelect Gender, case when gender='M' then 'Male' when gender='F' then 'Female' end as new_gender from tableMadhivananFailing to plan is Planning to fail |
 |
|
DonAtWork
Master Smack Fu Yak Hacker
2167 Posts |
Posted - 2008-01-28 : 11:46:39
|
Even better, follow the FIRST LINK in my signature. Read the ENTIRE page. Then, follow the directions on the page. You will get an answer VERY fast that way.[Signature]For fast help, follow this link:http://weblogs.sqlteam.com/brettk/archive/2005/05/25.aspxLearn SQL or How to sell Used CarsFor ultra basic questions, follow these links.http://www.sql-tutorial.net/ http://www.firstsql.com/tutor.htm http://www.w3schools.com/sql/default.asp |
 |
|
DonAtWork
Master Smack Fu Yak Hacker
2167 Posts |
Posted - 2008-01-28 : 11:53:09
|
[code]-- lets create our tablecreate table Gender ( GenType varchar(15))-- lets fill our table with datainsert into Gender select 'M' union allselect 'M'union allselect 'F'union allselect 'F'-- show what is in the tableSELECT * from GenderOUTPUT: MMFF-- run our updateUPDATE Gender set GenType = CASE GenType WHEN 'F' THEN 'Female' WHEN 'M' THEN 'Male'ELSE 'Unknown' END-- show what is in the tableSELECT * from GenderOUTPUT:MaleMaleFemaleFemale--dump this crapdrop table Gender[/code]It works for me. Dunno what your schema is like.[Signature]For fast help, follow this link:http://weblogs.sqlteam.com/brettk/archive/2005/05/25.aspxLearn SQL or How to sell Used CarsFor ultra basic questions, follow these links.http://www.sql-tutorial.net/ http://www.firstsql.com/tutor.htm http://www.w3schools.com/sql/default.asp |
 |
|
soori457
Yak Posting Veteran
85 Posts |
Posted - 2008-01-29 : 01:19:06
|
Thanks for ur replyIts workingSuresh Kumar |
 |
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2008-01-29 : 03:41:43
|
quote: Originally posted by soori457 Thanks for ur replyIts workingSuresh Kumar
How is it working now?What was wrong with your previous runs?MadhivananFailing to plan is Planning to fail |
 |
|
|