Define code sections in sql managment studio

Home / Uncategorized / Define code sections in sql managment studio

Question:
I have a very long script in sql. I’m working with SSMS 2012 and sql servr 2012.

The sturctre is somewhere like this:–Loans_Group
–2013
create view Loans_2013
(
select * from X where yr=2013
)
go

–2014
create view Loans_2014
(
select * from X where yr=2014
)
go
–2015
create view Loans_2015
(
select * from X where yr=2015
)
go
–2016
create view Loans_2016
(
select * from X where yr=2016
)
go
–2017
create view Loans_2017
(
select * from X where yr=2017
)
go

–Credit scoring Group

–2013
create view CS
(
select * from Y where yr=2013
)
go

–2014
create view CS where yr=2014
(
select * from Y
)
go

–2015
create view CS
(
select * from Y where yr=2015
)
go

–2016
create view CS where yr=2016
(
select * from Y
)
go

–2017
create view CS where yr=2017
(
select * from Y
)
go

create view Loans_Join as (
select * from Loans_2013
union
select * from Loans_2014
union
select * from Loans_2015
union
select * from Loans_2016
union
select * from Loans_2017
)
select * into Loans_Join_table from Loans_Join

create view CS_Join as (
select * from CS_2013
union
select * from CS_2014
union
select * from CS_2015
union
select * from CS_2016
union
select * from CS_2017
)
select * into CS_Join_table from CS_Join

create view FlatFile as (

select * from Loans_Join
left join CS_Join on Loans_Join.Cust = CS_Join.Cust

)
Now, Suppose I would like to create a Analysis Table only for 2014-2015. In order to that I will need to comment all the parts of code of the other years… including those parts in the views where I am union-ing all the views from all the years – Loans_Join and CS_Join. In my real code there are something like 20 groups beside Loans and CS. There is a reason why in order to create my Analysis Table I’m dividing it to parts of years and not using parameters. It’s a little long for me here to get into those reasons. I’m asking for an easy way I can set code sections and comment them when I execute the query. Something like this:
set code sections = (2013,2014,2015,2016,2017) comment Code_Sections = (2014,2015) and the press the F5 key.. Is someone know an option like that?


Answer:

Read more

Leave a Reply

Your email address will not be published. Required fields are marked *