I have a column called @months which stores months in this format
@month = ’01-03-05-11-12′
I would like to have a SELECT query that divides this column into 12, making it Jan, Feb, March
Each of my record has this column in front. So if a record has @month = ’01-03′ in it, it shows under January and March. Can something like that be done? Or anything close is good enough.
I played with case statement but could not produce the results.
Code if anyone wants to try
create table recs(
id int not null primary key,
cust_name varchar(20),
callmonth varchar(36)
)
insert into recs values(1,'john','01-12')
insert into recs values(2,'Jessica','02-06')
insert into recs values(3,'Charlie','01-06')
insert into recs values(4,'steale','03-04')
insert into recs values(5,'Silica','01-02-03-04-05-06-07-08-09-10-11-12')
insert into recs values(6,'Luder','01-03-05-07-09-11-12')
insert into recs values(7,'Panther','01-06-12')
insert into recs values(8,'Dinky','03-04-15')
I may be unclear about what you are trying to do, but you can devide into 12 tables using the following:
Do this for each month and it should give you 12 tables containing only the values that have that month. You could then use a view to combine them.
Alternatively, if you are looking for one query, you might be able to use a case statement like the one below:
This will yield a table with all fields from the original table, followed by 12 “monthly columns” each with a true or false representing whether that month is present in that row.