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.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 Getting only one row back

Author  Topic 

hog
Constraint Violating Yak Guru

284 Posts

Posted - 2005-10-28 : 09:59:04
I have my code as follows:

[code]
UPDATE A
SET 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'


Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

hog
Constraint Violating Yak Guru

284 Posts

Posted - 2005-10-28 : 10:09:52
Kool, cheers :)

Go to Top of Page

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'



Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

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 A
SET 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 ]



Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx
Go to Top of Page

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'


Madhivanan

Failing 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?



Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx
Go to Top of Page
   

- Advertisement -