Sqlserver
 sql >> Datenbank >  >> RDS >> Sqlserver

Wählen Sie Zeile aus, deren Spaltenausdruckswert Gültig ist

SELECT *, 
    CASE SUBSTRING(SlabExpression, PATINDEX('%[<,=,>]%', SlabExpression), PATINDEX('%[0-9]%', RIGHT(SlabExpression, LEN(SlabExpression) - PATINDEX('%[<,=,>]%', SlabExpression))))
        WHEN '<=' THEN 
            CASE WHEN CAST(LEFT(SlabExpression, PATINDEX('%[<,=,>]%', SlabExpression) -1) AS INT) <= CAST(RIGHT(SlabExpression, LEN(SlabExpression) - PATINDEX('%[<,=,>]%', SlabExpression) -1) AS INT) THEN 'True'
            ELSE 'False' END
        WHEN '=<' THEN 
            CASE WHEN CAST(LEFT(SlabExpression, PATINDEX('%[<,=,>]%', SlabExpression) -1) AS INT) <= CAST(RIGHT(SlabExpression, LEN(SlabExpression) - PATINDEX('%[<,=,>]%', SlabExpression) -1) AS INT) THEN 'True'
            ELSE 'False' END
        WHEN '>=' THEN 
            CASE WHEN CAST(LEFT(SlabExpression, PATINDEX('%[<,=,>]%', SlabExpression) -1) AS INT) >= CAST(RIGHT(SlabExpression, LEN(SlabExpression) - PATINDEX('%[<,=,>]%', SlabExpression) -1) AS INT) THEN 'True'
            ELSE 'False' END
        WHEN '=>' THEN 
            CASE WHEN CAST(LEFT(SlabExpression, PATINDEX('%[<,=,>]%', SlabExpression) -1) AS INT) >= CAST(RIGHT(SlabExpression, LEN(SlabExpression) - PATINDEX('%[<,=,>]%', SlabExpression) -1) AS INT) THEN 'True'
            ELSE 'False' END
        WHEN '>' THEN 
            CASE WHEN CAST(LEFT(SlabExpression, PATINDEX('%[<,=,>]%', SlabExpression) -1) AS INT) > CAST(RIGHT(SlabExpression, LEN(SlabExpression) - PATINDEX('%[<,=,>]%', SlabExpression) ) AS INT) THEN 'True'
            ELSE 'False' END
        WHEN '<' THEN 
            CASE WHEN CAST(LEFT(SlabExpression, PATINDEX('%[<,=,>]%', SlabExpression) -1) AS INT) < CAST(RIGHT(SlabExpression, LEN(SlabExpression) - PATINDEX('%[<,=,>]%', SlabExpression) ) AS INT) THEN 'True'
            ELSE 'False' END
        WHEN '=' THEN 
            CASE WHEN CAST(LEFT(SlabExpression, PATINDEX('%[<,=,>]%', SlabExpression) -1) AS INT) = CAST(RIGHT(SlabExpression, LEN(SlabExpression) - PATINDEX('%[<,=,>]%', SlabExpression) ) AS INT) THEN 'True'
            ELSE 'False' END
        ELSE null
        END AS Value
 FROM #TEMP