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)
 Selecting Top 1 as output param?

Author  Topic 

sherpa99
Starting Member

20 Posts

Posted - 2006-02-20 : 11:22:12
I'm trying to select a random single field/record with a query and return it as an output parameter. my query won't validate -- what's wrong? Is there a better approach?

thanks

-----------------------------------


CREATE PROCEDURE testCard_get
(
@ecomID int,
@cardNumber varchar(50) OUTPUT
)

AS

SELECT
@cardNumber = Top 1 a.cardNumber


FROM
cards a INNER JOIN card_bndDetails b
ON a.cardID = b.cardID

WHERE
a.used = 0
AND b.ecomID = @ecomID
AND a.shipEqualsBill IS NULL

ORDER BY
NEWID()
GO

TG
Master Smack Fu Yak Hacker

6065 Posts

Posted - 2006-02-20 : 11:31:21
just had the wrong order of keywords

SELECT top 1
@cardNumber = a.cardNumber
...


Be One with the Optimizer
TG
Go to Top of Page
   

- Advertisement -