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 |
TashiDuks
Starting Member
3 Posts |
Posted - 2014-01-07 : 03:51:51
|
Hi,I am using SQL SERVER 2008 and I have following tables :Table Name : tblParameterColumns : FYear = stores Current Financial Year CurrentYearYN = 0 for No, 1 for Yes MaxCL = Maximum Casual Leave value MinCL = Minimum Casual Leave ValueI need a stored procedure which will store next financial year in new row and set CurrentYearYN column value of previous year to 0 and set new financial year to 1 and copy the rest column value. After the stored procedure is run the table should have following value for example:Let say I am setting financial year 2014. After running stored procedure the table should look like this:FYear|CurrentYearYN|MaxCL|MinCL------------------------------2012 |0 |10 |0------------------------------2013 |0 |10 |0------------------------------2014 |1 |10 |0when ever I run the store procedure it should keep on adding new financial year and change the CurrentYearYN of previous year to 0 and set CurrentYearYN of new year to 1 and copy the rest.Sorry for the poor English. Hope the concept which I am looking for is clear.Need Help.ThanksTashiDuksLearn till you die... |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2014-01-07 : 06:27:02
|
something like thisCREATE PROC SetNewFYASUPDATE tSET CurrentYearYN = 0FROM Table tWHERE CurrentYearYN = 1INSERT TableSELECT TOP 1 FYear + 1,1,MaxCL,MinCLFROM TableORDER BY Fyear DESCGO ------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/https://www.facebook.com/VmBlogs |
|
|
TashiDuks
Starting Member
3 Posts |
Posted - 2014-01-08 : 02:02:22
|
Hi,Thanks its working. I need some more additional features. For example:Lets say the Current Year is Opened i.e. 2014. Can we add the validation if the current year is already opened. Since if there is not validation then whenever the Stored Procedure is run it keeps on adding new year.If yes then HOW? Please.ThanksLearn till you die... |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2014-01-08 : 06:44:10
|
Add a check as belowCREATE PROC SetNewFYASIF NOT EXISTS (SELECT 1FROM TableWHERE FYear = YEAR(GETDATE())AND CurrentYearYN = 1)BEGINUPDATE tSET CurrentYearYN = 0FROM Table tWHERE CurrentYearYN = 1INSERT TableSELECT TOP 1 FYear + 1,1,MaxCL,MinCLFROM TableORDER BY Fyear DESCENDGO ------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/https://www.facebook.com/VmBlogs |
|
|
|
|
|