| Author |
Topic |
|
zhshqzyc
Posting Yak Master
240 Posts |
Posted - 2009-01-14 : 15:59:08
|
Hello, I am trying to update a temp table.Can you look the code please?What's wrongselect @qry='update #tempset oper=(select tr.id from loan l inner join trans tron l.id=tr.idwhere tr.cd=44'exec(@qry) Thanks |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
|
sakets_2000
Master Smack Fu Yak Hacker
1472 Posts |
Posted - 2009-01-14 : 16:08:09
|
You have more than one number of rows being returned from your subquery,select tr.id from loan l inner join trans tron l.id=tr.idwhere tr.cd=44 If it were to return you one value, your query would work ok. Also, You needn't have your query dynamic in this case. \ |
 |
|
|
revdnrdy
Posting Yak Master
220 Posts |
Posted - 2009-01-14 : 16:11:58
|
| Your database table must have duplicate rows and the query is returning those.If you are unsure that the table contains duplicate rows try modifying this query and run it against your table.Note this query returns all duplicate rows of partnumbers for my Inventory system.SELECT manufacturer,partnumberFROM InventoryWHERE partnumberIN ( SELECT partnumberFROM InventoryGROUP BY partnumberHAVING Count(*) >1 )ORDER BY manufacturerIf you identify duplicate rows then you will have to come up with a business rule on how to handle them (delete or retain?).Also has the others have posted you do not need dynamic SQL.r&r |
 |
|
|
zhshqzyc
Posting Yak Master
240 Posts |
Posted - 2009-01-14 : 16:12:38
|
| It is from a stored procedure so I used dynamic sql.I want to update all rows.How to modify the query? |
 |
|
|
revdnrdy
Posting Yak Master
220 Posts |
Posted - 2009-01-14 : 16:14:32
|
| It depends on how you want to handle duplicate rows.. |
 |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
|
zhshqzyc
Posting Yak Master
240 Posts |
Posted - 2009-01-14 : 16:17:24
|
| Just ignore the dynamic SQL code and duplicate rows. I can discard it later on.Now how to return all rows? |
 |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
|
zhshqzyc
Posting Yak Master
240 Posts |
Posted - 2009-01-14 : 16:27:29
|
| Well, if it is still from #temp t.I worry it can't be updated. |
 |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
|
zhshqzyc
Posting Yak Master
240 Posts |
Posted - 2009-01-14 : 16:45:19
|
| Thanks.It works out. |
 |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
|
|