Skip to content
Snippets Groups Projects

Update medication_days_covered.sql with try_convert logic to handle varchar errors

Closed Dziobek, Jim C. requested to merge jcd71_medFix into main
1 file
+ 2
2
Compare changes
  • Side-by-side
  • Inline
@@ -18,7 +18,7 @@ with medication_strength as (
* IF: Only characters in string, return '1'
* ELSE: Subset the string to just the numeric part
*/
convert(NUMERIC(18, 4),
try_convert(NUMERIC(18, 4),
case
when patindex('%[^0-9.,]%', value) = 0 then replace(value, ',', '')
when patindex('%[^0-9.,]%', value) = 1 then '1'
@@ -29,7 +29,7 @@ with medication_strength as (
* IF: Only characters in string, return full string
* ELSE: Subset the string to just the character part and clean
*/
convert(VARCHAR,
try_convert(VARCHAR,
case
when patindex('%[^0-9.,-]%', value) = 1 then value
when charindex(' ', ltrim(substring(value, patindex('%[^0-9.,-]%', value), len(value)))) > 0
Loading