sql >> Database teknologi >  >> RDS >> Sqlserver

Vælg række, hvis kolonneudtryksværdi er gyldig

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  


  1. SQL 2008 - varchar(max) vs tekstdatatyper

  2. begyndervejledning til rapportfremviser?

  3. Escape-streng til brug i MySQL fuldtekstsøgning

  4. Identifikator 'APEX_JSON.PARSE' skal erklæres i oracle 11.2.0