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 |
|
a.ashabi
Posting Yak Master
117 Posts |
Posted - 2009-03-23 : 18:09:44
|
| Hi.When I used my query to update a field like this:UPDATE itemsSET items.ITEMDocJ =(SELECT docjonson.ITEMDocJFROM dbo.docjonson INNER JOIN dbo.items ON dbo.docjonson.ITEMNew=dbo.items.ItemNewWHERE dbo.items.ItemNew=dbo.docjonson.ITEMNew)I got this error :Subquery returned more than 1 value. This is not permitted when the subquery follows =, !=, <, <= , >, >= or when the subquery is used as an expression.The statement has been terminated.So I removed all the duplications from both tables:-- DELETE DUPLICATES FROM docjonsonSELECT docjonson.ITEMNew , COUNT(*) AS Expr1into DocKeysFROM (dbo.docjonson INNER JOIN dbo.items ON dbo.docjonson.ITEMNew = dbo.items.ItemNew)GROUP BY docjonson.ITEMNew HAVING count(*) > 1SELECT DISTINCT docjonson.*INTO docDupFROM docjonson, DocKeysWHERE docjonson.ITEMNew = DocKeys.ITEMNewDELETE docjonsonFROM docjonson, DocKeysWHERE docjonson.ITEMNew = DocKeys.ITEMNew-- DELETE DUPLICATES FROM itemsSELECT DISTINCT items.*INTO itemsDocDupFROM items, DocKeysWHERE items.ITEMNew = DocKeys.ITEMNewDELETE itemsFROM items, DocKeysWHERE items.ITEMNew = DocKeys.ITEMNewNow I cant find any duplicates on the tables but when I try to update still I've got the same error.What should I do?what is wrong with my query?Plz help me.thanks in advanced. |
|
|
revdnrdy
Posting Yak Master
220 Posts |
Posted - 2009-03-23 : 20:20:08
|
Helloquote: Originally posted by a.ashabiUPDATE itemsSET items.ITEMDocJ =(SELECT docjonson.ITEMDocJFROM dbo.docjonson INNER JOIN dbo.items ON dbo.docjonson.ITEMNew=dbo.items.ItemNewWHERE dbo.items.ItemNew=dbo.docjonson.ITEMNew)
Is the part in red necessary? Seems redundant to me..r&r |
 |
|
|
a.ashabi
Posting Yak Master
117 Posts |
Posted - 2009-03-24 : 13:27:53
|
| It worked for some other tables when I've added the red satatement.But this time I have the error with or without the red statement. |
 |
|
|
vijayisonly
Master Smack Fu Yak Hacker
1836 Posts |
Posted - 2009-03-24 : 14:23:12
|
| This is what you need probably...UPDATE itemsSET items.ITEMDocJ = docjonson.ITEMDocJFROM dbo.docjonson INNER JOIN dbo.items ON dbo.docjonson.ITEMNew=dbo.items.ItemNew |
 |
|
|
a.ashabi
Posting Yak Master
117 Posts |
Posted - 2009-03-24 : 14:52:00
|
| yes.that was the right query.thanks u so much :) |
 |
|
|
vijayisonly
Master Smack Fu Yak Hacker
1836 Posts |
Posted - 2009-03-24 : 15:09:41
|
| np |
 |
|
|
|
|
|