sql - Case statement errors with unneccessary conversion -



sql - Case statement errors with unneccessary conversion -

i'm scripting view, shown below, i'm experiencing issues lastly 5 selects. i'm pulling table int values contains nulls. i'd null values these 'rep' columns outputted 'n/a' logic in case statements throwing errors trying convert n/a int.

i think somewhere along line in case statements, it's setting nulls n/a , trying add together values onto int appreciate help might falling over.

many thanks!

select --name exercisecultures.name, --weight case when weight null '0' else case when type = 'isolation' case when reps1 < '12' , reps2 < '12' , reps3 < '12' weight else case when exercisecultures.name in ( 'hammer curls', 'concentration curls' ) workoutsessions.weight + ( 2.0 ) else workoutsessions.weight + ( 2.5 ) end end else case when type = 'compound' case when name = 'bench press' case when reps1 < '3' , reps2 < '3' , reps3 < '3' weight else workoutsessions.weight + ( 2.5 ) end else case when reps1 < '5' , reps2 < '5' , reps3 < '5' weight else workoutsessions.weight + ( 2.5 ) end end end end end weight, -- reps1 case when reps1 = null 'n/a' else case when type = 'isolation' case when reps1 < '12' , reps1 >= '8' reps1 + ( 1 ) else '8' end else '5' end end reps1, -- reps2 case when reps2 null 'n/a' else case when type = 'isolation' case when reps2 < '12' , reps2 >= '8' reps2 + ( 1 ) else '8' end else '5' end end reps2, --reps3 case when reps3 null 'n/a' else case when type = 'isolation' case when reps3 < '12' , reps3 >= '8' reps3 + ( 1 ) else '8' end else '5' end end reps3, --reps4 case when reps4 null 'n/a' else case when type = 'isolation' case when reps4 < '12' , reps4 >= '8' reps4 + ( 1 ) else '8' end else '5' end end reps4, --reps5 case when reps5 null 'n/a' else case when type = 'isolation' case when reps5 < '12' , reps5 >= '8' reps5 + ( 1 ) else '8' end else '5' end end reps5 workoutsessions bring together exercisecultures on workoutsessions.exerciseid = exercisecultures.exerciseid bring together workoutdates on workoutsessions.workoutid = workoutdates.workoutid , workoutdates.date = (select max(date) workoutdates workouttype = 'pull')

try converting integer types, varchar types before doing conditional statements. can either creating variable/temp table, specifying columns varchar - , extracting info temporary table or if not want that, have cast each integer column in query this...

case when cast(reps1 varchar(100)) = null 'n/a' else

sql sql-server tsql sql-server-2014

Comments

Popular posts from this blog

formatting - SAS SQL Datepart function returning odd values -

c++ - Apple Mach-O Linker Error(Duplicate Symbols For Architecture armv7) -

php - Yii 2: Unable to find a class into the extension 'yii2-admin' -