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 |
|
hog
Constraint Violating Yak Guru
284 Posts |
Posted - 2005-10-28 : 09:59:04
|
| I have my code as follows:[code]UPDATE ASET A.po_due_date = (SELECT FIRST (due_date) FROM dbo.releases AA WHERE AA.part_no = A.part_no AND AA.location = 'TMW') FROM @ResultSet A[code/]This requires a single result from the select statement. How do I force the select statement to return only a single value if more than one is going to be returned? I tried to find something like first in Access but have had no joy!Thnx |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2005-10-28 : 10:00:57
|
| SELECT Top 1 (due_date) FROM dbo.releases AA WHERE AA.part_no = A.part_no AND AA.location = 'TMW'MadhivananFailing to plan is Planning to fail |
 |
|
|
hog
Constraint Violating Yak Guru
284 Posts |
Posted - 2005-10-28 : 10:09:52
|
| Kool, cheers :) |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2005-10-28 : 10:14:57
|
| Did this return same value?SELECT due_date FROM dbo.releases AA WHERE AA.part_no = A.part_no AND AA.location = 'TMW'MadhivananFailing to plan is Planning to fail |
 |
|
|
X002548
Not Just a Number
15586 Posts |
Posted - 2005-10-28 : 10:32:52
|
quote: Originally posted by hog I have my code as follows:[code]UPDATE ASET A.po_due_date = (SELECT FIRST (due_date) FROM dbo.releases AA WHERE AA.part_no = A.part_no AND AA.location = 'TMW') FROM @ResultSet A[code/]This requires a single result from the select statement. How do I force the select statement to return only a single value if more than one is going to be returned? I tried to find something like first in Access but have had no joy!Thnx
ummm...the slash(/) in the code tag goes in front[code ] [/code ]Brett8-)Hint: Want your questions answered fast? Follow the direction in this linkhttp://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx |
 |
|
|
X002548
Not Just a Number
15586 Posts |
Posted - 2005-10-28 : 10:34:43
|
quote: Originally posted by madhivanan SELECT Top 1 (due_date) FROM dbo.releases AA WHERE AA.part_no = A.part_no AND AA.location = 'TMW'MadhivananFailing to plan is Planning to fail
TOP 1 without an ORDER BY is meaningless, dangerous and misleading all at the same time...Do you have an actual requirement we could follow?Brett8-)Hint: Want your questions answered fast? Follow the direction in this linkhttp://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx |
 |
|
|
|
|
|