?
Solved

sql query help

Posted on 2013-01-16
1
Medium Priority
?
159 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 2000 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

NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

Question has a verified solution.

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

What if you have to shut down the entire Citrix infrastructure for hardware maintenance, software upgrades or "the unknown"? I developed this plan for "the unknown" and hope that it helps you as well. This article explains how to properly shut down …
It is possible to export the data of a SQL Table in SSMS and generate INSERT statements. It's neatly tucked away in the generate scripts option of a database.
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function
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.
Suggested Courses

752 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