SQL Operators as text in where clause

Posted by suggy1982 on Stack Overflow See other posts from Stack Overflow or by suggy1982
Published on 2011-06-27T11:28:05Z Indexed on 2011/06/27 16:22 UTC
Read the original article Hit count: 240

Filed under:
|
|
|

I have the following table, which is used for storing bandings. The table is maintained via a web frontend.

CREATE TABLE [dbo].[Banding](
[BandingID] [int] IDENTITY(1,1) NOT NULL,
[ValueLowerLimitOperator] [varchar](10) NULL,
[ValueLowerLimit] [decimal](9, 2) NULL,
[ValueUpperLimitOperator] [varchar](10) NULL,
[ValueUpperLimit] [decimal](9, 2) NULL,
[VolumeLowerLimitOperator] [varchar](10) NULL

The operator fields store values such as > < >= <=. I want to get to a position where I can use the operators values stored in the table in a case statement in a where clause. Like this.

SELECT * FROM table WHERE CASE ValueLowerLimitOperator
WHEN '<' THEN VALUE < X
WHEN '>' THEN VALUE > X END

rather than having to write mutiple case or if statements for each permutation.

Does anyone have any suggestions how I can decode the operators values stored in the table as part of my query and then use them in a case/where statement?

© Stack Overflow or respective owner

Related posts about sql

Related posts about sql-server-2005