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.

 All Forums
 SQL Server 2012 Forums
 Transact-SQL (2012)
 Create automatically stored procedure

Author  Topic 

fatys
Starting Member

3 Posts

Posted - 2014-10-07 : 08:30:46
Hi all,
I am new to this forum and I start with stored procedure.

here's my problem:
I would like to create a stored pocedure that manages quarters of the year and which automatically triggered at the beginning of each quarter.

I have a table in my database that stores the quarter.

Id Default Q Begin End
1 1 NULL NULL NULL
2 0 2 1 3
3 0 3 4 6
4 0 4 7 9
5 0 1 10 12


Here the function which i set up to update the order of quarters (this is done by using the Column Q and begin ), it is written in C # but it is not automatically :

public List<PeriodList> OrderPeriod(List<PeriodList> list, PeriodList period)
{
if (!period.Default)
{
// Q
if (period.Id == GetCurrentMonth())
{
period.Q = 1;
}
// Q+1
if (period.Begin + 3 <= 12)
{
list.Single(tmp => tmp.Begin == period.Begin + 3).Q = 2;
}
else
{
list.Single(tmp => tmp.Begin == period.Begin - 9).Q = 2;
}
// Q+2
if (period.Begin + 6 <= 12)
{
list.Single(tmp => tmp.Begin == period.Begin + 6).Q = 3;
}
else
{
list.Single(tmp => tmp.Begin == period.Begin - 6).Q = 3;
}
// Q+3
if (period.Begin + 9 <= 12)
{
list.Single(tmp => tmp.Begin == period.Begin + 9).Q = 4;
}
else
{
list.Single(tmp => tmp.Begin == period.Begin - 3).Q = 4;
}
}
return list.OrderBy(pr => pr.Q).ToList();
}

- The order of quarters allows me to update data from other tables.
- How can I trigger the stored each quarter beginning of a procedure (eg early January, early April ...)

Thank you in advance

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2014-10-07 : 12:27:12
I am not sure if I understand your post, but if you want something to run quarterly, then just schedule a job to do it.

Tara Kizer
SQL Server MVP since 2007
http://weblogs.sqlteam.com/tarad/
Go to Top of Page

fatys
Starting Member

3 Posts

Posted - 2014-10-08 : 03:20:06
Thank you for your reply.

I read that there are in the link but it does not reponds to my post.
Go to Top of Page

gbritton
Master Smack Fu Yak Hacker

2780 Posts

Posted - 2014-10-08 : 08:57:22
Maybe you mistyped this sentence:

"I read that there are in the link but it does not reponds to my post."

I cannot understand what you mean here.
Go to Top of Page
   

- Advertisement -