Solved

sql query help

Posted on 2013-01-16
1
158 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

MIM Survival Guide for Service Desk Managers

Major incidents can send mastered service desk processes into disorder. Systems and tools produce the data needed to resolve these incidents, but your challenge is getting that information to the right people fast. Check out the Survival Guide and begin bringing order to chaos.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
In the first part of this tutorial we will cover the prerequisites for installing SQL Server vNext on Linux.
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.

726 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