Ask a Question related to Dreamweaver AppDev, Design and Development.
-
TJ Bristol #1
Tricky Stored Procedure...
Hey,
As always any insight appreciated.
I am building a live auction app where people can leave absentee bids which
are then calculated during the live auction when the lot comes up.
I need to build a stored procedure that will pull the highest bid with the
lowest timestamp (this would be the winner, as in a tie the first person to
bid that amount would win) and the next lower or equal bid (or <=) to
compare it to and calculate the opening bid based on the amount of the bid.
The losing bid can be the same value as the winning bid, the winner having
the lower timestamp as he/she bid the amount first.
Here's what I have come up with so far to get the "winner":
CREATE PROCEDURE spProxy(@auctionID NUMERIC, @lotID NUMERIC)
AS
SELECT dbo.TAB_BIDS.usrID, bid, dbo.TAB_USERS.username FROM dbo.TAB_BIDS
INNER JOIN dbo.TAB_USERS ON dbo.TAB_BIDS.usrID = dbo.TAB_USERS.usrID WHERE
bid = (SELECT MAX(bid) FROM TAB_BIDS WHERE auctionID = @auctionID AND
lotID= @lotID AND absent = 1)
AND bidtime = (SELECT MIN(bidtime) FROM TAB_BIDS)
GO
This falls over and gives no records...I also need to find a way to pull
the"loser" at the same time...Any Ideas?
Thanks in advance
TJ Bristol Guest
-
MS SQL stored procedure
I am new to MS SQL server and stored procedures. I currently have a query that looks like: select from table where fieldname IN... -
Using a stored procedure
I am trying to pass a ProdID to a stored procedure, but I get an error: Error Executing Database Query. Procedure 'PriceBreak' expects... -
Stored procedure?
Stored procedure ?? -- Message posted via http://www.dotnetmonster.com -
help with a stored procedure
I am new to postgres stored procedures and would like a little help. My function basically takes 2 arguments and inserts data into a table from a... -
Stored procedure from stored procedure
Is it possible to create a stored procedure from a stored procedure? When I attempt this inanity, it doesn't blow up until syntax error at the... -
TJ Bristol #2
Re: Tricky Stored Procedure...
Got it sorted:
SELECT top 2 with ties
dbo.TAB_BIDS.usrID,
bid,
bidtime,
dbo.TAB_USERS.username
FROM
dbo.TAB_BIDS
INNER JOIN
dbo.TAB_USERS
ON dbo.TAB_BIDS.usrID = dbo.TAB_USERS.usrID
WHERE
auctionID = @auctionID
AND lotID= @lotID
AND absent = 1
order by
bid desc,
bidtime asc
TJ Bristol Guest



Reply With Quote

