I have a CSV, I want to get the SUM of all the values in it, I couldn't find a good solution.
I have thought to try STRING_SPLIT
like the below, But It requires compatibility level 130 and my SQL Server is on 120. I cannot change the compatibility level.
DECLARE @csv VARCHAR(MAX) = '1,2,3,4,5';
SELECT SUM(*) FROM STRING_SPLIT(@csv, ','); --It should return 15
SQL Server details:
Microsoft SQL Server 2019 (RTM-CU9) (KB5000642) - 15.0.4102.2 (X64)
Jan 25 2021 20:16:12 Copyright (C) 2019 Microsoft Corporation Developer Edition (64-bit) on Windows Server 2019 Datacenter 10.0 (Build 17763: ) (Hypervisor)