Hi! I have posted this in slack support channel but I am not sure if that’s the correct place. Apologies if I am mistaken.
Can anyone point to the right direction with jinja? I am very lost with it. I want to do a simple function where a number is calculated using dates. This is an sketch about how I would do it in SQL, any links/tutorials welcome. I have not been able to find something related, not even in dbt documentation or through this discourse. Thank you!!
CREATE FUNCTION test.get_account_age ( trade_type VARCHAR(20), account_number INT ) RETURNS INT BEGIN DECLARE account_age INT; DECLARE date_diff INT; DECLARE datetime_check1 DATETIME; DECLARE datetime_check2 DATETIME; #get date to use based on trade type IF trade_type = 'type1' THEN SELECT datetime_check1 = orderdatekey FROM ordertable; # if trade type, etc... END IF; #get global date SELECT datetime_check2 = first_date FROM accounttable # get difference between dates SET date_diff = DATEDIFF(month, datetime_check1, datetime_check2); # calculate account age IF date_diff < 12 THEN SET account_age = 1; #ELSE IF date_diff >= 12 AND date_diff < 24 THEN # SET account_age = 2; ELSE SET account_age = 0; END IF; RETURN (account_age); END