I have a situation in SQL server 2012 and I need to query a different column in a table based on a variable. So I have a table and the columns have a bld_type field and 3 additional columns that are specific to the year. The columns with the year contain either an A or I.
So the table is set up like this
testtable
bld_type bld_2015 bld_2016 bld_2017
123 A A I
124 A A I
126 I A I
I have a stored procedure that is going to compare a variable that I get from an outside source to the bld_type based on the year that the project is produced.
I have tried if year = 2015 then select bld_type from testtable where bld_2015 = 'A'
and this works fine and I have even said else and had a different select statement checking bld_2016 = 'A'.
The rub comes in when I try to put this into another if construct. The first example would have produced 123,124. And what I need to do is add the code to this if statement
if @TRM_type not in (my code from above)
begin @errorcount = @errorcount + 1 end
In other words, when I try to embed an if statement inside an if statement it does not want to work. Am I missing a bracket or an end in some way?
Thanks in advance for any help.