diff --git a/example_usage.pg.sql b/example_usage.pg.sql index 6acdb14..070e365 100644 --- a/example_usage.pg.sql +++ b/example_usage.pg.sql @@ -4,7 +4,17 @@ FROM pricequote.single_price_call( 'FARM0001', 'KEYB0001', 'HZP3E103E21D050', - 'v1:T..BDL..', + 'v1:C..BDL..', + 50000 +) f + +SELECT + ui_json->'details' +FROM pricequote.single_price_call( + 'FARM0001', + 'KEYB0001', + 'HZP3E103E21D050', + 'v1:C..BDL..', 50000 ) f diff --git a/procs/single_price_call.ms.sql b/procs/single_price_call.ms.sql index 82323b7..edb5760 100644 --- a/procs/single_price_call.ms.sql +++ b/procs/single_price_call.ms.sql @@ -475,7 +475,9 @@ BEGIN ) ELSE '' - END AS note + END + + CASE WHEN last_isdiff <> '' THEN ' | normalized to: ' + cast(last_price_norm AS varchar(10)) ELSE '' END + AS note FOR JSON PATH -- array with one object (no WITHOUT_ARRAY_WRAPPER) ) AS details diff --git a/procs/single_price_call.pg.sql b/procs/single_price_call.pg.sql index c1ef653..ed30b70 100644 --- a/procs/single_price_call.pg.sql +++ b/procs/single_price_call.pg.sql @@ -464,26 +464,26 @@ BEGIN ELSE NULL END ) ) - -- ||CASE WHEN _last_premium IS NOT NULL THEN - ||COALESCE(jsonb_build_array(jsonb_build_object( + ||CASE WHEN COALESCE(_last_premium,1) <> 1 THEN + COALESCE(jsonb_build_array(jsonb_build_object( 'label','Price Difference', 'value', _last_premium, 'type','percent', 'note', _last_premium_method )),'[]'::jsonb) - -- ELSE - -- '[]'::jsonb - -- END - -- ||CASE WHEN _last_premium IS NOT NULL THEN - ||COALESCE(jsonb_build_array(jsonb_build_object( + ELSE + '[]'::jsonb + END + ||CASE WHEN COALESCE(_last_premium,1) <> 1 THEN + COALESCE(jsonb_build_array(jsonb_build_object( 'label','Adjusted Price', 'value', _last_price_norm, 'type','currency', 'note','normalized to ' || _v1ds )),'[]'::jsonb) - -- ELSE - -- '[]'::jsonb - -- END + ELSE + '[]'::jsonb + END ), ------------------------------------------ -- price list