Query Help

  • How to Create a stored procedure to find the following output.

    [Q1 = Jan + Feb + Mar ][ Q3 = July + Aug + Sept]

    I need to calculate the Q1 = Jan + Feb + Mar(2011) and Q3 = July + Aug + Sept

    2011/Q1 2011/Q3

    Last Year This Year Last Year This Year

    Emp1 Salary

    Emp2 Salary

    ... … … … …

    Emp n Salary

    Total ∑ ∑ ∑ ∑

    I need to calculate the Salary of employee i.e [Q1 = Jan + Feb + Mar ] and [Q3 = July + Aug + Sept] of 2011

    Thanks

  • suresh0534 (4/2/2012)


    How to Create a stored procedure to find the following output.

    [Q1 = Jan + Feb + Mar ][ Q3 = July + Aug + Sept]

    I need to calculate the Q1 = Jan + Feb + Mar(2011) and Q3 = July + Aug + Sept

    2011/Q1 2011/Q3

    Last Year This Year Last Year This Year

    Emp1 Salary

    Emp2 Salary

    ... … … … …

    Emp n Salary

    Total ? ? ? ?

    I need to calculate the Salary of employee i.e [Q1 = Jan + Feb + Mar ] and [Q3 = July + Aug + Sept] of 2011

    Thanks

    Hello and welcome to SSC!

    I'd like to be able to help, but it seems you've forgot to post readily consumable sample data and ddl scripts.

    If you could read this article[/url] about the best way to post DDL and sample data then edit your post to include it, it would be extremely useful for the unpaid volunteers of this site.

    Thanks!


    Forever trying to learn
    My blog - http://www.cadavre.co.uk/
    For better, quicker answers on T-SQL questions, click on the following...http://www.sqlservercentral.com/articles/Best+Practices/61537/
    For better, quicker answers on SQL Server performance related questions, click on the following...http://www.sqlservercentral.com/articles/SQLServerCentral/66909/

  • I posted a solution on a similar topic quite recently here:

    http://qa.sqlservercentral.com/Forums/Topic1273926-392-2.aspx

    Perhaps this will help you, perhaps not. Depends on your incoming data format and exactly how you need your expected results organized.

    As Cadavre suggests, posting DDL and some readily consumable sample data will no doubt deliver a high quality solution to your question in a very short span of time.

    Hope this helps.


    My mantra: No loops! No CURSORs! No RBAR! Hoo-uh![/I]

    My thought question: Have you ever been told that your query runs too fast?

    My advice:
    INDEXing a poor-performing query is like putting sugar on cat food. Yeah, it probably tastes better but are you sure you want to eat it?
    The path of least resistance can be a slippery slope. Take care that fixing your fixes of fixes doesn't snowball and end up costing you more than fixing the root cause would have in the first place.

    Need to UNPIVOT? Why not CROSS APPLY VALUES instead?[/url]
    Since random numbers are too important to be left to chance, let's generate some![/url]
    Learn to understand recursive CTEs by example.[/url]
    [url url=http://www.sqlservercentral.com/articles/St

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply