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 |
|
antifreze
Starting Member
5 Posts |
Posted - 2008-04-07 : 16:27:50
|
| Hello all,Ive been tasked with writing a SQL query to move information from 2 tables(old1 and old2) into 1(new). table new already has all the information from old1, but also has some additional columns that are encompassed from old2. Also some of the columns in table new need to be assigned a 1 or a 0 if the information is present in old2. Here is what I came up with:UPDATE new SET new.IsRentalLocation = 1 new.IsMainCampus = 1 new.IsLearningCenter = 1 new.IsStudentResource = 1 new.AlternateStateDisp = 0 new.Directions = tbl_old2.Directions new.Catering = tbl_old2.Catering new.Lab = tbl_old2.LabFROM new, old1, old2WHERE new.CampusID = old1.CampusIDAND old1.LearningCenterID = old2.LearningCenterID Does this look right? or should I be using an insert command? |
|
|
jhocutt
Constraint Violating Yak Guru
385 Posts |
Posted - 2008-04-07 : 16:34:56
|
| Assuming that new does not actually have data but just structure than you will need an insert."God does not play dice" -- Albert Einstein"Not only does God play dice, but he sometimes throws them where they cannot be seen." -- Stephen Hawking |
 |
|
|
antifreze
Starting Member
5 Posts |
Posted - 2008-04-07 : 16:40:49
|
| there is data in there. Most of old1's data has already been moved to new. |
 |
|
|
antifreze
Starting Member
5 Posts |
Posted - 2008-04-07 : 17:34:16
|
| So I ran this, but it didnt filter anything out like the "where" statements were suppose to. I got a lot of duplicated informationDo I need to something in the SET like new.Catering = SELECT tbl_old2.Catering WHERE new.CampusID = old1.CampusIDAND old1.LearningCenterID = old2.LearningCenterID? |
 |
|
|
antifreze
Starting Member
5 Posts |
Posted - 2008-04-07 : 17:38:06
|
| so that broke it... got an error:The text, ntext, and image data types cannot be compared or sorted, except when using IS NULL or LIKE operator |
 |
|
|
|
|
|