I just want to know how you deal with long scripts and redundant information. Here is an example:
Suppose you have three tables:
And you have
SELECT id = 1 org = 'company' name = 'name' addr = 'arr' lang = 1 cnt1 = if col1 = 1 then 1 else 1 cnt2 = if col2 = 1 then 1 else 1 cnt3 = if col2 = 1 then 1 else 1 INTO table1 FROM sometable SELECT id = 2 org = 'company2' name = 'name' addr = 'arr' lang = 1 cnt1 = if col1 = 1 then 1 else 1 cnt2 = if col2 = 1 then 1 else 1 cnt3 = if col2 = 1 then 1 else 1 INTO table2 FROM sometable
So the difference is that the starting stuff (not the
cnt* fields) are changing. But as you can see there is a lot of overlap.
Also if I want to change the logic on the counts (which are common to both), then i have to go through both select statements and change them manually. this is error prone.
I was thinking something along this pseudocode:
SELECT id = 1 org = @variable name = @variable addr = 'arr' lang = 1 INCLUDE other columns/logic from somewhere else INTO table2 FROM sometable
that way, if my logic changes for the
cnt fields, I can just change it in one spot and it would change everywhere.
I am open to any suggestions. SMSS addin, stored procs, or some other ugly or beautiful method people know.