Thank you All!!
I think at this point I am willing to be hunted down by the PB Coding Police.
I created a stored procedure, but not really sure if it works. The first part of the SQL seems to work fine in the DB Painter, but I need to get the rank only for the affiliate that is logged in (sp_id) and that is why it is an input parameter:
USE LIMO
GO
CREATE PROCEDURE dbo.ft_sp_RankAffiliateRate2 @sp_id nvarchar(10), @a_identity numeric, @b_identity numeric, @vehicle_type int, @rate_rank int OUTPUT
AS
-- create the table variable
declare @raterank table (sp_id char(10) not null, a_identity numeric not null, b_identity numeric not null, ar_vehicle_type int not null, ar_total_from_airport money not null, ar_rate_rank int not null, rate_rank int not null)
insert into @raterank (sp_id,
a_identity,
b_identity,
ar_vehicle_type,
ar_total_from_airport,
ar_rate_rank,
rate_rank)
select sp_id,
a_identity,
b_identity,
ar_vehicle_type,
ar_total_from_airport,
ar_rate_rank,
DENSE_RANK() OVER(ORDER BY ar_total_from_airport) rate_rank
from ft_affiliate_rate_staged
where ft_affiliate_rate_staged.a_identity = @a_identity and
ft_affiliate_rate_staged.b_identity = @b_identity and
ft_affiliate_rate_staged.ar_vehicle_type = @vehicle_type
select rate_rank from @raterank where sp_id = @sp_id
GO
I created a test workspace to call the stored procedure, but I can't quite make that part work:
I cannot save the code with the fetch statement as PB tells me "Database C0038: SQLSTATE = 22005[Microsoft][ODBC SQL Server Driver]Invalid character value for cast specification". I can save the code in the button script if I remove the Fetch related statements, but then there is no way to get the value of @rate_rank. Again, thanks very much for any and all help!!! Paul
Button Script:
int rate_rank
string sp_id
long a_identity
long b_identity
int vehicle_type
sp_id = 'F10600'
a_identity = 23864
b_identity = 4018
vehicle_type = 1
DECLARE ft_sp_RankAffiliateRate2_pb procedure for ft_sp_RankAffiliateRate2
@sp_id = :sp_id,
@a_identity = :a_identity
@b_identity = :b_identity
@vehicle_type = :vehicle_type
@rate_rank = :rate_rank OUTPUT;
IF SQLCA.SQLCode <> 0 THEN
MessageBox ( "Error", "DECLARE failed" )
RETURN -1
END IF
execute ft_sp_RankAffiliateRate2_pb;
DO WHILE SQLCA.SQLCODE = 0
FETCH @rate_rank
INTO :rate_rank
LOOP
IF ( SQLCA.SQLCode <> 0 ) and ( SQLCA.SQLCode <> 100 ) THEN
MessageBox ( "Error", "EXECUTE failed" )
RETURN -1
END IF
//rate_rank = @rate_rank
close ft_sp_RankAffiliateRate2_pb;
messagebox("Rate Rank","Rate Rank for " + sp_id + " is: " + string(rate_rank))