473,395 Members | 1,404 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,395 software developers and data experts.

how do i use conditional statement in sql?

3
how do i use conditional statement in sql? im using access 2003 as frontend and backend.

What would be the SQL statement for the situation below?

I would like to count the number of records in a table (ex. ENROLL) where there is only 1 instance of any value in a field (ex. STUDENT_NO) plus another condition where a given value (ex. 1) should exist in another field (ex. SECTION).

Example
Table name: ENROLL

STUDENT_NO SECTION FEE
16 ------------------ 1 -------- 75
16 ------------------ 2 -------- 75
17 ------------------ 1 -------- 100
18 ------------------ 2 -------- 125
19 ------------------ 1 -------- 75
19 ------------------ 2 -------- 75
19 ------------------ 3 -------- 75
20 ------------------ 1 -------- 150

Parameters:

COUNT
The number of records (count) in the table where there is only one instance of the STUDENT_NO value and the corresponding SECTION value is 1

VALUE
The sum of the FEE values in the table where there is only one instance of the STUDENT_NO value and the corresponding SECTION value is 1


The answer should come out like this:
count = 2
value = 250
Mar 29 '07 #1
5 2415
Rabbit
12,516 Expert Mod 8TB
how do i use conditional statement in sql? im using access 2003 as frontend and backend.

What would be the SQL statement for the situation below?

I would like to count the number of records in a table (ex. ENROLL) where there is only 1 instance of any value in a field (ex. STUDENT_NO) plus another condition where a given value (ex. 1) should exist in another field (ex. SECTION).

Example
Table name: ENROLL

STUDENT_NO SECTION FEE
16 ------------------ 1 -------- 75
16 ------------------ 2 -------- 75
17 ------------------ 1 -------- 100
18 ------------------ 2 -------- 125
19 ------------------ 1 -------- 75
19 ------------------ 2 -------- 75
19 ------------------ 3 -------- 75
20 ------------------ 1 -------- 150

Parameters:

COUNT
The number of records (count) in the table where there is only one instance of the STUDENT_NO value and the corresponding SECTION value is 1

VALUE
The sum of the FEE values in the table where there is only one instance of the STUDENT_NO value and the corresponding SECTION value is 1


The answer should come out like this:
count = 2
value = 250
Expand|Select|Wrap|Line Numbers
  1. SELECT Count(*) As Count, Sum([Fee]) As Value
  2. FROM [Table Name]
  3. WHERE ((DCount("*", "[Table Name]", "STUDENT_NO = " & STUDENT_NO) = 1) AND (SECTION = 1));
Mar 29 '07 #2
bamn68
3
Expand|Select|Wrap|Line Numbers
  1. SELECT Count(*) As Count, Sum([Fee]) As Value
  2. FROM [Table Name]
  3. WHERE ((DCount("*", "[Table Name]", "STUDENT_NO = " & STUDENT_NO) = 1) AND (SECTION = 1));
Thanks very much, Rabbit. That solve it when the STUDENT_NO data type is a number. I am getting an error because the data type for the STUDENT_NO field is text.
Mar 30 '07 #3
Rabbit
12,516 Expert Mod 8TB
If it's text then use:
Expand|Select|Wrap|Line Numbers
  1. SELECT Count(*) As Count, Sum([Fee]) As Value
  2. FROM [Table Name]
  3. WHERE ((DCount("*", "[Table Name]", "STUDENT_NO = '" & STUDENT_NO & "'") = 1) AND (SECTION = 1));
Mar 30 '07 #4
bamn68
3
Thanks again, Rabbit. You're great!!! I got it working now.
Mar 30 '07 #5
Rabbit
12,516 Expert Mod 8TB
Not a problem, good luck.
Mar 30 '07 #6

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

Similar topics

7
by: Shaldaman | last post by:
I have an Access form called "Login". "Command10" is a button on the form and "Text5" is a text field on it. When a user enters a value in the Text5 text field and clicks the button Command10, I...
8
by: arganx | last post by:
The conditional statement "if(j.... always executes regardless of what you enter. BOOL CALLBACK EnumWindowsProc(HWND hwnd,LPARAM lParam) { char buffer=""; GetWindowText(hwnd,buffer,256);...
5
by: Gary Wessle | last post by:
Hi if I have a method like this bool myClass::myMothod(myType& mt, herType ht) throw ( SomeExp ); how can I use it in a conditional statement if ( try {
43
by: dev_cool | last post by:
Hello friends, I'm a beginner in C programming. One of my friends asked me to write a program in C.The purpose of the program is print 1 to n without any conditional statement, loop or jump. ...
0
by: cljordan | last post by:
I am trying to create a database that list materials and their quantities, and highlights quantities that come up outside a certain percentage range against the average. I have tried the following...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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?
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.