T-SQL : using parameter as an operator

Viewed 372

Is there a way to parameterize the arithmetic operators (<, >, =, >=, <=) in T-SQL?

Something like this:

DECLARE @Operator 

SET @Operator = '>=' 

SELECT * 
FROM Table 
WHERE Date @Operator '7/1/2017'

Also, I am testing to add additional parameter using functions EXEC('SELECT SiteLongName, * FROM Reporting.Survey_Details WHERE CallDate ' + @Operator + '''7/1/2017''' + 'and SiteLongName in (select value from dbo.FnSplit(''' + @Site + ''''+'',''+'','')) , but it is erroring out.

1 Answers
Related