On tsql, I want to use variable as part of tsql code according to some conditions, is there a way to do the following:
DECLARE @mode BINARY = 0
DECLARE @stringCode VARCHAR(100)
.
.
.
if(@mode = 1)(
@stringCode VARCHAR(100) = 'charindex(",", rtrim(col1_name), col2_name)'
)ELSE(
@stringCode VARCHAR(100) = '1=1'
)
SELECT col1_name, col2_name, col3_name
FROM table1_name AS T1
INNER JOIN table2_name AS T2
ON @stringCode
The last query using the variable @stringCode as part of the code.
Well, it did not work like that, so I wanted to know if I could possibly apply this?
Please note that this code is just a test to demonstrate what I want to do