I have this code in SQL Server, and I want to convert it Snowflake supported code. Issue is in update part. Create procedure part can be done.
CREATE PROCEDURE [SchemaA].[UpdateRecords]
(
@ExtractID bigint,
@AgencyID bigint
)
AS
BEGIN
DECLARE
@TransID bigint
SET @TransID = 0
UPDATE
[SchemaA].[TransactionTable]
SET
@TransID = [TID] = (@TID + 1)
FROM
[SchemaA].[TransactionTable] t1
LEFT OUTER JOIN
[SchemaB].[ClientTable] t2 ON t2.[AgencyID] = @AgencyID
AND [SchemaA].[ConvertIDToString](t1.[ClientID]) = t2.[ClientCode]
LEFT OUTER JOIN
[SchemaA].[InvoiceTable] t3 ON t3.[ExtractID] = @ExtractID
AND t1.[InvoiceNumber] = t3.[InvoiceNumber]
LEFT OUTER JOIN
[SchemaB].[PolicyTable] t4 ON t4.[AgencyID] = @AgencyID
AND [SchemaA].[ConvertIDToString](t3.[PolicyNumber]) = t4.[PolicyCode]
LEFT OUTER JOIN
[SchemaB].[BrokerTable] t5 ON t5.[AgencyID] = @AgencyID
AND t1.[BrokerID] = t5.[BrokerCode]
LEFT OUTER JOIN
[SchemaB].[DepartmentTable] t6 ON t6.[AgencyID] = @AgencyID
AND (t3.[DivisionID] + t3.[BranchID] + t3.[DeptID]) = t6.[DeptCode]
WHERE
t1.[ExtractID] = @ExtractID
END
I want this in Snowflake, the issue is Snowflake doesn’t support left join in update.
I have tried this approach:
update t1
set v = 0
where t1.id in (
select t4.id
from t4 left join t3
on t4.id = t3.id
left join t2 on t3.id = t2.id
left join t1 on t2.id = t1.id);
Is this correct?
1