473,396 Members | 1,871 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Need help on my query(sql statement)...

hi all,

I'm having a hard time producing the correct sql statement for my tables.
below is my sql statement but i'm getting incorrect result. This particular query returns the sum of all the value of a particular field and it seems that it is ignoring the parameter which is entirely wrong.

Hope somebody can help me...thank you in advance.

Expand|Select|Wrap|Line Numbers
  1. SELECT RTRIM (tbl_Students.Id_No) AS IdNo, RTRIM(LastName) + ', ' + RTRIM(FirstName) + ' ' + LEFT(MiddleName,1) AS Names, 
  2.                  RTRIM(tbl_Courses.Abbreviation) + '/' + RTRIM(tbl_EnrollStatus.YearLevel) + '/' + RTRIM(tbl_EnrollStatus.Section) AS CrsYrSec, 
  3.                  ((SUM(ISNULL(AssessedAmount, 0)) + SUM(ISNULL(tbl_AssessedFees.AdjustDebit,0))) - SUM(ISNULL(tbl_AssessedFees.AdjustCredit, 0))) AS AssessedAmt,
  4.                  SUM(ISNULL(tbl_Payments.Amount, 0)) AS PaymentAmt, 
  5.                  ((SUM(ISNULL(AssessedAmount, 0)) + SUM(ISNULL(tbl_AssessedFees.AdjustDebit,0))) - (SUM(ISNULL(tbl_AssessedFees.AdjustCredit, 0)) + SUM(ISNULL(tbl_Payments.Amount, 0)))) AS RemainingBalance  
  6.                  FROM tbl_Students.Id_No INNER JOIN tbl_CourseTaken ON tbl_Students.ID_No = tbl_CourseTaken.Id_No 
  7.                      INNER JOIN tbl_Curriculum ON tbl_CourseTaken.Curriculum_Code = tbl_Curriculum.Curriculum_Code 
  8.                       INNER JOIN tbl_Courses ON tbl_Curriculum.Course_Code = tbl_Courses.Course_Code 
  9.                       INNER JOIN tbl_EnrollStatus ON tbl_CourseTaken.Taken_Code = tbl_EnrollStatus.Taken_Code 
  10.                       INNER JOIN tbl_Enrollees ON tbl_EnrollStatus.Enroll_Code = tbl_Enrollees.Enroll_Code 
  11.                       INNER JOIN tbl_AssessedFees ON tbl_EnrollStatus.Enroll_Code = tbl_AssessedFees.Enroll_Code 
  12.                       LEFT JOIN tbl_Payments ON tbl_EnrollStatus.Enroll_Code = tbl_Payments.Enroll_Code 
  13.                      INNER JOIN tbl_ReceiptNo ON tbl_Payments.Receipt_Code = tbl_ReceiptNo.Receipt_Code 
  14.                  WHERE tbl_Enrollees.Schedule_Code = @schedCode AND 
  15.                        tbl_ReceiptNo.PayStatus = 'Valid' 
  16.                  GROUP BY tbl_Students.Id_No, LastName, FirstName, MiddleName, tbl_Courses.Abbreviation. tbl_EnrollStatus.YearLevel, 
  17.                        tbl_EnrollStatus.Section 
  18.                 ORDER BY tbl_Names ASC
Nov 26 '07 #1
1 1091
debasisdas
8,127 Expert 4TB
Are you sure the table contains data for desired output . Can you please post your table structures.
Nov 29 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: lowellturner | last post by:
We recently had to reload an app to a Linux server from its Window counterpart. I've tried setting the lower case global in my.cnf to al three values, but none work. Previously, this worked fine....
3
by: Ajay | last post by:
hi All, I am writing a java application which queries DB2. I need SQL queries for following : 1. Query to check whether, the attributes for LOB columns like BLOB and CLOB is "LOGGED" or not?...
8
by: Bill | last post by:
Hello out there; This may be a challenge but I'm certain it's possible but I can't seem to figure out how. I have a table that has several date fields, e.g., Date1, Date2, Date3, Date4 ......
1
by: Michael | last post by:
Hi, I've read Scott's article: http://weblogs.asp.net/scottgu/archive/2005/08/25/423703.aspx but when I try to create a new database file in App_Data with Visual Studio 2005, it shows error: ...
0
by: getkapilcs | last post by:
Hi, i want to query sql server using xml, where the required fields are to be specified in the xml dynamically. can you tell me how to generate such a xml file? regards, Kap
5
by: Karthik D V | last post by:
Hello All, I have a table like this ID CHARACTER ----------- --------- 1 A 2 A 3 B 4 B
9
by: Access | last post by:
In my user interface if a user doesn't have access to a field in the database I lock it and make the background color yellow. Problem is I'm maintaining permissions in two different places. On...
0
by: Dinesh | last post by:
Hi, Currenly we need SQL Server Database Admin, about 2 yrs of experience. Position is based on Dubai and this is permanent position with Carrefour (2nd largest Hypermarket after Walmart). If...
1
by: jeffatncx | last post by:
Hi all ms Access 2003, SP2. I write a SQL statement that unions some other queries and it works ok. Then, if I save and close it and open the form that uses the query as its data source, I get an...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.