Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
junior6202
Starting Member
45 Posts |
Posted - 2015-04-06 : 22:36:16
|
I have a question, Every month I get a request from cutomer service to go into a SQL VIEW and DELETE a column to reflect the past Month. Can anybody advice on how to write a query to create a SQL job to performed this task automatically. For example today I deleted the column [2015/03] which represents the month of March. The columns left are [2015/04] representing the current month, [2015/05], [2015/06],[2015/07]....[2016/08].Next month I will have to delete column [2015/04]and the current month will be [2015/05]....etc. So I'm thinking I will have to Drop the column and also Maybe using a date funtion to look at the current date and format it to reflect [YYYY/MM] and IF the Column Month is less than current date month then drop the column. Any Ideas will be appreciated. Thanks in advance.Junior |
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2015-04-07 : 02:50:41
|
You can't delete columns like that from a view. You will have to open the view with ALTER and then make the necessary changes. Microsoft SQL Server MVP, MCT, MCSE, MCSA, MCP, MCITP, MCTS, MCDBA |
|
|
Kristen
Test
22859 Posts |
Posted - 2015-04-07 : 08:14:58
|
YOu could use Dynamic SQL instead of a VIEW ... no idea if that would fit into your application or other usage of this view though.You could generate the VIEW each month with some sort of application code / scheduled task. |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
|
|
|
|