Solved

sql query help

Posted on 2013-01-16
1
156 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Why is this different from all of the other step by step guides?  Because I make a living as a DBA and not as a writer and I lived through this experience. Defining the name: When I talk to people they say different names on this subject stuff l…
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…
Using examples as well as descriptions, and references to Books Online, show the different Recovery Models available in SQL Server and explain, as well as show how full, differential and transaction log backups are performed
Via a live example, show how to shrink a transaction log file down to a reasonable size.

680 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