I have the the following piece of SQL COALESCE ( REPLACE ( STR( coSalesCatalogI.SCtlgIndCode, 14 ), ' ', '0' ), '00000000000000' )
which can only handle NULL, 0, ' ' or numerics at present but there are new text entries in this field so i'm trying to write a test case expression(below) which can handle each scenario as it does at the min but if the field is text i just want to return it without doing any formatting to it.DECLARE @NUM VARCHAR(20), @NUM1 VARCHAR(20), @NUM2 VARCHAR(20), @NUM3 VARCHAR(20), @NUM4 VARCHAR(20)SET @NUM = '0'--SET @NUM = ' '--SET @NUM = '035600701300544'--SET @NUM = 'EAN-14 FUN PARK'--SET @NUM = 'NULL'SELECT CASE @NUM WHEN ('0', 'NULL', ' ') THEN '00000000000000' WHEN ISNUMERIC (@NUM) = 1 THEN REPLACE (STR( @NUM, 14 ), ' ', '0' ) WHEN ISNUMERIC (@NUM) = 0 THEN @NUM END
Any help would be appreciated.