| Author |
Topic |
|
meef
Posting Yak Master
113 Posts |
Posted - 2011-04-05 : 15:59:27
|
I have a column that gets a '0' by default and a '1' if it was billed. How can I change that column for all records to have a '1' in it after they get billed? Would it just be something like this?update table_name set column_name = expression where search_conditions |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
|
meef
Posting Yak Master
113 Posts |
Posted - 2011-04-06 : 08:46:05
|
Well I couldn't figure out how to join a table in an update statement, so I put it off and now have to go through 331 record one at a time to update them.Two things, how can I ask it to find many different data in the same column? Quite literally I need something like where bol_number = '1111', '1113', '1116', etc. I know that won't work, but I'm going to have to hand type them all in, I just don't know how to have it look for 300 specific things like that.Second question is how do I join a table in an update statement? |
 |
|
|
GilaMonster
Master Smack Fu Yak Hacker
4507 Posts |
Posted - 2011-04-06 : 08:48:22
|
| Update Table1SET <whatever>FROM Table1 INNER JOIN Table2 ON ....WHERE bol_number IN ('1111','1113','1116', ... )--Gail ShawSQL Server MVP |
 |
|
|
webfred
Master Smack Fu Yak Hacker
8781 Posts |
Posted - 2011-04-06 : 08:50:33
|
Give example table structure(s) with example data and wanted output please because then we are able to answer all your questions without having to guess... No, you're never too old to Yak'n'Roll if you're too young to die. |
 |
|
|
meef
Posting Yak Master
113 Posts |
Posted - 2011-04-06 : 09:52:37
|
Ok, I tried this:use databaseupdate table1set g.billed = 1from table1 b inner join table2 g on b.bol_id=g.bol_idWHERE (b.bol_number IN ('longstringofnumbers'))At the g.billed = 1, it's telling me it can't be bound. Not sure why it's saying that, the column is in table2, it seems like it's only looking in table 1.I'm also pretty sure I'll have to update table 2 also, maybe that's why it's only looking at table 1, that's the only one I'm telling it to update right now. |
 |
|
|
webfred
Master Smack Fu Yak Hacker
8781 Posts |
Posted - 2011-04-06 : 09:56:21
|
You say that the column is in table2 but your statement is "update table1" ... hm... No, you're never too old to Yak'n'Roll if you're too young to die. |
 |
|
|
meef
Posting Yak Master
113 Posts |
Posted - 2011-04-06 : 10:03:35
|
quote: Originally posted by webfred You say that the column is in table2 but your statement is "update table1" ... hm... No, you're never too old to Yak'n'Roll if you're too young to die.
Yep, see my edit in the last post. How do I also update the joined table? I suppose I only need to update table2 is that's where the column is... duh.Never mind, thanks for the help :) |
 |
|
|
|