Hi, I have a lengthy query here, and wondering whether it could be refactor?
Declare @A1 as int
Declare @A2 as int
...
Declare @A50 as int
SET @A1 =(Select id from table where code='ABC1')
SET @A2 =(Select id from table where code='ABC2')
...
SET @A50 =(Select id from table where code='ABC50')
Insert into tableB
Select
Case when @A1='somevalue' Then 'x' else 'y' End,
Case when @A2='somevalue' Then 'x' else 'y' End,
..
Case when @A50='somevalue' Then 'x' else 'y' End
From tableC inner join ......
So as you can see from above, there is quite some redundant code. But I can not think of a way to make it simpler.
Any help is appreciated.