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 |
|
LOOKUP_BI
Constraint Violating Yak Guru
295 Posts |
Posted - 2011-03-23 : 17:48:35
|
| Hi,I have 3 table as such and need to perform an updateTable Vehicle [Primary Key =VID]VID VName VType1 Volvo Wagon2 BMW SUV3 Audi Sedan4 Merc Van5 Saab SedanTable Type [No Primary Key]TypeID TType TGroup11 Wagon Wagon12 SUV SUV13 Lux Sedan Sedan14 Van Van14 Mini Van Van13 Comp Sedan SedanTable Vehicle_Type [Join table Vehicle + Type]VID GroupID1 02 03 04 05 0Relationships Vehicle_Type.VID = Vehicle.VIDVehicle.VType=Type.TGroupI need to update column GroupID in Vehicle_Type by joining the followingUPDATE Vehicle_Type set GroupID =( SELECT TGroup from Type T INNER JOIN Vehicle V ON V.VType=T.TGroup INNER JOIN Vehicle_Type VT ON VT.VID=V.VID)I get an error Subquery returned more than 1 value. This is not permitted when the subquery follows =, !=, <, <= , >, >= or when the subquery is used as an expression.I think this Update is wrong, can someone guide me.Thank You |
|
|
yosiasz
Master Smack Fu Yak Hacker
1635 Posts |
Posted - 2011-03-23 : 18:03:14
|
yes the update is wrong. anyways here is an update you could tryUPDATE tgt SET GroupID = TGroup FROM Vehicle_Type tgtINNER JOIN Vehicle V ON VT.VID=V.VIDINNER JOIN Type T ON V.VType=T.TGroup question to you: Why do you not have a primary key for group and why are you using 0 for groupID?If you don't have the passion to help people, you have no passion |
 |
|
|
LOOKUP_BI
Constraint Violating Yak Guru
295 Posts |
Posted - 2011-03-24 : 10:03:55
|
| Thank You Yosiasz.It worked perfectly for meThe value '0' for the GroupId is being defaulted from the front end. That is the reason we need to update the GroupId after with the correct values.We have gone ahead and create a PK on table Type [ Type ID + TType] column. |
 |
|
|
yosiasz
Master Smack Fu Yak Hacker
1635 Posts |
Posted - 2011-03-24 : 11:08:04
|
| Why not create a table with those group values and feed the front end with a drop down of those values. next time someone wants a new group you are going to change the front end? not sustainable design IMHOIf you don't have the passion to help people, you have no passion |
 |
|
|
|
|
|