Solved

sql query help

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

VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

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…
This article shows gives you an overview on SQL Server 2016 row level security. You will also get to know the usages of row-level-security and how it works
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties
Via a live example, show how to set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.

776 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