Solved

sql query help

Posted on 2013-01-16
1
151 Views
Last Modified: 2013-02-04
I have  2 tables as below: and all i need is the totalmount of the amount table for the current fiscalyear from the meeting-date for a request
   
    Table Request
    Requestno  meetingdate
    LOT        01/15/2012
    BOR        12/15/2008
    CEB        01/25/2012  
   
    Table Amount
    Requestno  totalamount  FY
    LOT                100         2012
    LOT         200         2013
    LOT         400         2012  
    BOR         500         2013             

and the results should be:
    CBRno    totalamount
    LOT      500
    BOR      0
   
and I came with a fiscalyear calucultio from internet:  
YEAR(DATEADD(month, 6 + DATEDIFF(month, 0,
g.meetingdate), 0))

KIndly help me with the query in pulling the required data, i want one row for a request
0
Comment
Question by:welcome 123
1 Comment
 
LVL 22

Accepted Solution

by:
Steve Wales earned 500 total points
ID: 38784846
The following will give you the answer you're looking for (Assuming column FY is a char(4) column):

select a.requestno, sum(case when fy = convert(char(4), year(dateadd(month, 6+datediff(month, 0, a.meetingdate), 0))) then b.totalamount else 0 end)
from request a
join amount b 
on a.requestno = b.requestno
group by a.requestno

Open in new window

0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

When you hear the word proxy, you may become apprehensive. This article will help you to understand Proxy and when it is useful. Let's talk Proxy for SQL Server. (Not in terms of Internet access.) Typically, you'll run into this type of problem w…
Slowly Changing Dimension Transformation component in data task flow is very useful for us to manage and control how data changes in SSIS.
Viewers will learn how the fundamental information of how to create a table.
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now