first off, let me show you the query:
INSERT INTO @Table
SELECT TOP 1
ID AS 'TicketID',
tblRoundsID AS 'tblRoundsID',
tblUsersID AS 'UserID'
FROM dbo.tblTicketHeaders
WHERE tblRoundsID = tblRoundsID
AND tblUsersID = @UserIDWinner
AND Canceled = 0
AND dbo.calcPayOutAmount(ID, tblRoundsID, tblClientsID) > 0
ORDER BY (SELECT new_id FROM GetNewID) -- randomizes the rows
what i want to acomplish here is to select one random ticket(row) where calcpayoutamount is > 0, but since this function is not so fast, i dont want to check all rows for payout amount, just until one random one is found,
so if this was working like i intended, the usage time should be everytime different, i tested it multiple times, it returns 12-14 seconds for specific paremeter, so im assuming it calls the calcpayoutamount for every row, in which it doesnt help me, i want it to be called, until at least one row is found.
again: i hope you can understand what i want to accomplish here... .. so, call calcPayOutAmount until (>0) is found, but i also need the randomization ... which is order by line... i really hope you understood me, please ask if something i need to add for more info...
Aucun commentaire:
Enregistrer un commentaire