Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
rob41
Yak Posting Veteran
67 Posts |
Posted - 2010-10-22 : 10:42:36
|
| How would i update a column with values from multiple columns.I'm trying to update reason with values from load, ship, weightload only has values of 1 or 0ship only has values of 1 or 0and weight only has values of 1 or 0if load = 1if ship = 1if weight = 1i want the reason column to have a value of load ship weight |
|
|
maevr
Posting Yak Master
169 Posts |
Posted - 2010-10-22 : 17:37:49
|
| You could just convert the different columns to varchar and concaternate the strings. Just use query below in update.select cast(load as varchar(1)) + cast(ship as varchar(1)) +cast(weight as varchar(1)) as reasonfrom tbl where load = 1and ship = 1and weight = 1 |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2010-10-23 : 01:47:54
|
| so if all are 1 you want value of column as 111? what kind of design is that?------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
rob41
Yak Posting Veteran
67 Posts |
Posted - 2010-10-23 : 10:13:42
|
| what i was trying to get is an update query that would update a row called codes with information from other columns, see below:UPDATE [RC]SET [RC].[CODE] = 'LMRC'FROM [RC]where LMRC = 1UPDATE [RC]SET [RC].[CODE] = 'XPD'FROM [RC]where XPD = 1UPDATE [RC]SET [RC].[CODE] = 'ACDT'FROM [RC] RESULT SHOULD BEID CODE111 LMRC XPD ACDT888 XPD777 LMRC ACDT1 IS JUST A FLAG THAT MEANS IT'S A VALID CODE |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2010-10-27 : 13:45:35
|
| how did 888 and 777 came in between? your initial post values as 0 or 1------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
TimSman
Posting Yak Master
127 Posts |
Posted - 2010-10-27 : 14:09:08
|
| If I'm understanding this right, you want a column that shows which attribute flags are set. I may be wrong, but that's how I read it. |
 |
|
|
|
|
|