Need Help How To Construct Query With Conditional Statement

Mar 29, 2007

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

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


Can anybody please help me to construct the SQL statement?

Thanks in advance!

View Replies


ADVERTISEMENT

Queries :: Way To Construct A Query From Selected Inputs

Nov 27, 2014

I have a form with several fields and combo boxes on which the user will select different criteria to generate a report.The default value for each of these fields/cbo's is "*", so if the user changes nothing from the default, I execute a basic "SELECT *" query.

If however the user enters some value (selects a specific date range, customer number, salesman,etc), I would like to 'easily' modify my query to accommodate the entered search criteria.Trying to construct SQL when there are many search options like this is difficult. I took a stab at using QueryDefs but I'm struggling to find example VBA code as an example.

View 1 Replies View Related

How To Construct Dynamically A Table Field Based On Query Criteria.

Sep 13, 2007

Hello all,

I have a temporary table with Yes/No fields (F101,F102,F103,....etc).
In another table i have a field called ProductCode with values (101,102,103,....etc)
Is it possible to append(or update) the records of the temp table with criteria on "F" &ProductCode field? (For example if ProductCode=101 then F101 sets to yes)

Thank you in advance.

View 4 Replies View Related

Modules & VBA :: Construct A Query With Number Of DCounts For Summary Report

Dec 16, 2014

I am trying to construct a query with a number of DCounts for a summary report, and each of those counts is to have more than one criteria.So far, the code below is an example of the code, which returns #Error in five rows

Code:
DCount("[ID]","Attendance","[Absent]= True & " And [Date]=" Between [Forms]![DateSelect]![txtStartDate] And [Forms]![DateSelect]![txtEndDate]")

I have a feeling that it is the criteria for the date that I have got wrong, but I cannot see the wood for the trees at the moment.If it makes any difference, all of the DCounts will refer to one table and will all be within the same date range.

View 11 Replies View Related

Help With Conditional Statement

Dec 27, 2007

Hi,

I have an access database that contains information on donations made to our non profit organization.

I'm wondering how I query for people who have donated in categories (a,b,c) between 01/01/05 - 01/01/07, but have NOT donated in categories (a,b,c) in >01/02/07.

In other words I'm trying to sort out the people who have donated to us in certain categories in the past, but have not yet done so this year.

There are fields in my tables for donor id, as well as donation type, and donation date.

Any help or info is appreciated!

View 7 Replies View Related

How To Create Conditional Statement

Sep 6, 2005

I guess I need to create an if else statement for one of my fields in a query. The query basically calculates a dollar amount from certain fields in one of my tables and sums them together at the end with an expression.

I also have a true/false field in the same table. and if it's true then the expression in my query must equal 0, if false then it sum up the fields. Do I need to create a module for this or is it possible to do this directly in query? And if so, how?

Thanks,

View 2 Replies View Related

Conditional Statement Problem

Feb 14, 2008

Hi All,

I'm relatively new to Access and having some difficulty using conditional statements - if anyone could help I'd really appreciate it.

Basically I want to take an order summary table (OrderData) that shows total orders over different date ranges and expand them to show the average order per day for each product.

I'm using two queries to do this, the first finds the average per day for each record (Demand) using this formula: Expr: Sum(([OrderData]![orderamount])/([OrderData]![EndDate]-[OrderData]![StartDate]+1)) That part works fine.

The second query then needs to lookup each individual date of the year against the date range on the original data table, and if the date falls within the range, places the daily average from the prior query in a column.

I had been trying to use this - Expr: iif([Output]![Date] Between [OrderData]![Start] And [OrderData]![End], [Demand]![OptimalAverage],"0") but it's not working.

Any ideas?

View 1 Replies View Related

Conditional Statement Troubles..

Feb 14, 2008

Hi All,

I'm relatively new to Access and having some difficulty using conditional statements - if anyone could help I'd really appreciate it.

Basically I want to take an order summary table (OrderData) that shows total orders over different date ranges and expand them to show the average order per day for each product.

I'm using two queries to do this, the first finds the average per day for each record (Demand) using this formula: Expr: Sum(([OrderData]![orderamount])/([OrderData]![EndDate]-[OrderData]![StartDate]+1)) That part works fine.

The second query then needs to lookup each individual date of the year against the date range on the original data table, and if the date falls within the range, places the daily average from the prior query in a column.

I had been trying to use this - Expr: iif([Output]![Date] Between [OrderData]![Start] And [OrderData]![End], [Demand]![OptimalAverage],"0") but it's not working.

Any ideas?

View 12 Replies View Related

Need Help With Junction Table(s) Construct

Apr 13, 2007

I'm working in the petro-chem and industrial service industries now, and am finding there are relationships I haven't had much exposure to in the past.

Can someone please help me with constructing the tables and relationships needed here?

This is something I should probably know, yet I've never created junction tables which must take into account nested data. I have created a relationship which works, but I feel it could be done in a simpler fashion.

By the way, I cannot find Pat Hartman's many-to-many sample db. It is either missing, or the restrictions on word length in Search just aren't letting me find it.

Table: WorkOrder is the primary table I'm working with. I need to store 4
pieces of information for every WorkOrderID, two of which have subs.

Here's a picture of the data I need to collect:

View 4 Replies View Related

Modules & VBA :: How To Construct String For Variable

Sep 10, 2013

I am trying to set the following variable that will be used to create a PDF file in an already existing folder and name the file WorkorderIDddmmyyyy-hhnnss.pdf

The following variable setting creates the filenameddmmyyyy-hhnnssWorkorderID.pdf.

mFilename = "C:RPR AccessPDF Reports Emailed" & Format(Now(), "ddmmyyyy-hhnnss") & WorkorderID & ".pdf"

DoCmd.OutputTo acOutputReport, mReportName, acFormatPDF, mFilename, True

I just can't figure out how to construct it correctly.

Also, is there a way to dynamically create a folder if the folder doesn't already exist? I currently hard code the folder name but would really like to create the folder name based upon some other variable.

View 8 Replies View Related

Conditional Query Using Between

Jul 13, 2006

Hi - I wonder if anyone could possibly help, I have a list box that is populated by a query, which currently populates the list according to which site is selected within a combobox - what i would like to do in addition is to have a check box which controls how much data is shown, ie, if the checkbox is ticked show all data from April 1st onwards, if not ticked to only show the last 12 weeks (84 days)

I have tried to acheive this using the code below:

[Forms]![frmPccAnalysis]![cboSelect] --is used to select the site--

IIf([Forms]![frmPccAnalysis]![chkFilterLimit]=-1,(Between #01/04/2006# And Now()),(Between (Now()-84) And Now())) --is what i am trying to use to either restrict or show all data--

when i run the code i just get empty fields, if i manually enter the "Between #01/04/06# and Now()" statement in the criteria it works fine, just not with the conditial checkbox. Can anyone please point me in the right direction?

Many Thanks

Ian

View 4 Replies View Related

Conditional Query??

Aug 24, 2007

My Access is very rusty and I really can't get my head round how to do this!

I have a simple caller i.d. system which detects incoming telephone calls. I have been running an append query where the incoming call number is a query parameter against a table of customer numbers and names. The append query basically adds call numbers, names and times to a call log table.

This all works fine! ...however I realise that if the incoming call number is not in the table of customers numbers and names, no log entry is created. What I wish to do is, if the number is not found to append it anyway together with the time of call. Basically if the query fails to find a result, append details anyway albeit without a customer name.

I'm sure this must be simple but I'm going round in circles. Any thoughts anyone?

Thanks

View 3 Replies View Related

Conditional Query?

Nov 30, 2007

i have a query from 2 table. let's say table a & b. i have one form to show the query. the query show data based on what enter on the form.

when someone enter a value, on form, the query use it as filter for displaying data. my problem is one field of my query show data from the second table.
if input is AA, the data will be shorted by AA plus showing first colum of table 2.
if input is AB, the data will be shorted by AB plus showing second colum of table 2. etc.

so far, i make several query for each kode to display the corect column.
can i use 1 query to do that? if not, what should i use? macro/module? please the example aslo.

thanks

View 1 Replies View Related

Conditional Query

Jan 10, 2005

Hi,

I have a query that combines fields with an IIF statement adding a comma as the seperator "," is it possible to put a condition on it so that if a field had soley an integer or even a string with a value of 4 or less characters that the comma will be excluded, so for example:

A1 A2
1 Parlmont avenue

changes to:
1, Parlmont avenue

want it to change to:
1 Parlmont avenue

this is how the IIF statement looks like:
IIF(IsNull([I1].[A1]),[I1].[A2],[I1].[A1] & IIf(IsNull([A2]),"",", " & [A2])) AS Expr2

where I1 is table and A1,A2 are first and 2nd fields respectively, any suggesetions very much appreciated.

M-.

View 7 Replies View Related

Conditional Formatting Query

Mar 19, 2006

I have a query that brings up a job#, its start date (mm/dd/yyyy), and its
priority status (Low, Medium, or High).

Is there SQL I can use to make another query that will look at the start date,
and if it is a week old, change the priority status to Medium, and if it's a
month old, change the priority to High?

Thanks!!:)

View 4 Replies View Related

Conditional Formating Of Query

Jul 7, 2006

HI
I am working on a database that holds communications from treatment episodes.
the sub form holds the communications related to that client and that treatment episode.
when you enter a date into the communication record a mesage box asks if this is a new treatment episode and if yes opens a new treatment record. If it is the same treatment episode it just remind you that you are in the same treatment episode.
what i would like to do as an additional cue to the user is that once a client has been discharged from the episode that all communication records change color.
I can get the field that says dc to change color but I want all the fields in all the records from that episode to change color.
any ideas?
thanks

View 1 Replies View Related

Query Conditional Criteria

Jul 10, 2006

Hi guys,

I have a form with an option group. It has 2 options. The first one has a value of 1, the second has a value of 2. This option group is named "category".

Separate from this I have a query with several fields. In one of these fields, I need to enter a criteria that enters "LOE*" if the option group value is 1, or if the value is 2, I need it to enter "IDC*" in the criteria. My form that the option group is on is named "SelectWell". This is what I have tried so far:

Like IIf([Forms]![SelectWell]![category]=1,"LOE *","IDC*")

This works correctly if the option group value is 2, but doesn't work for the 1 value (LOE*).

Thanks,
Chris

View 2 Replies View Related

Query With Conditional Criteria

Sep 21, 2006

Hi, I have the following situation:

I have two tables: userdata and superusers and a function username() which can be used for acquiring the username of the active user.

Table userdate contains a column 'username'. With the following SQL query the active user can obtain the records from the userdata table belonging to himself with a query like:


SELECT * FROM userdata
WHERE userdata.username = username()

Now, what I want to do is that IF the username (obtained using the function call (username()) exists in table superusers ALL records have to be shown, just with:


SELECT * FROM userdata

I want to do everyting with only one query, so that if the query is executed either all records from userdata are shown (when username is in superusers table) or only the ones that belong to the users.

Is there something like a conditional statement to create a conditional WHERE statement, or maybe another solution to solve this problem?

Thanks in advance.

View 5 Replies View Related

Conditional From 2 Tables In Query

Jan 3, 2007

Happy new year all. I have 2 tablesI have a query that if any tbl2.num=tbl1.num AND tbl2.action = 'confirmed' this row should be selected for deletion from tbl1. I've tried linking the tables and using an iif statement, but no good and I'm not sure what else to do- any ideas?Forgot to add- tbl1.num might or might not exist on tbl2

View 2 Replies View Related

Conditional Formatting With A Query?

Feb 28, 2007

I have a query set up to prompt users when their license will expire (30 days out). Problem is that there are 2 types of licenses and some have different dates. I would like to have a report where I could see all the people that are about to expire either it be one license or the other or both. Thank you please help.

View 1 Replies View Related

Query To Calculate Conditional Field

Feb 5, 2007

Dear all,

I have a query that is based on orders table and contains "Qty", 'UnitCost', and "ctualUnitCost", in addition to yes/no control to indicate if "SalesTax" is applicable.

I want an expression in the query to calculate total cost in one of 2 conditions:
if no sales tax then TotalCost = Qty*UnitCost
if sales tax is applicable then Total cost = Qty*UnitCost*1.1

how can I write this expression

thanks

View 2 Replies View Related

How To Write Conditional Expression In Query?

Mar 16, 2005

Hi,

I have problem in creating conditional expression for query table. I want to add IF Else statement in the statement so that if the value is more than 50, a new field called grade will display the grade of "A" in the new field.

Can anyone teach me how to write conditional expression.

Thanks
Dawn

View 4 Replies View Related

Conditional Query For Selecting Different Fields For Each Record

Oct 17, 2007

I have an interesting report query I am working on. Is it possible to have a query that shows different fields for individual records depending on the content of the record? Let me see if I can explain. Let's say that I have a Status field that can be "Complete", "Active", or "Planned". And lets say also in that table I have Field1, Field2, and Field3. For each record, I don't want to include all three fields (Field1, Field2, Field3), but only one of these fields depending on what is in the Status field.

So, it would be something like:

Select Status, (if Status = "Complete", select Field1), (if Status = "Planned", select Field2), (if Status = "Active", select field3) FROM table;

So, the query would result in 2 fields for each record: the status field, and one of the three other fields depending on what is in the status field for that record.

Thank you kindly for your help.

View 2 Replies View Related

Queries :: Conditional Change To Date Query?

Feb 13, 2014

i need to clean up a date field (I hate dates in access!). The field in the table (imported from a spreadsheet) has records where users have simply entered a date in the correct format and then others where users feel obliged to add comments after the date rather in the 'Comments' section. Therefore Cdate alone won't work.

So far i have tried:

Code:

IIf(Len([TabDL].[PROMISE]<>10),#1/1/1900#,CDate([TabDL].[PROMISE])) AS PromiseDt1

The intention being to insert a holding date 01/01/1900 if the field contains too many characters to be a date alone. I've tried multiple variations of this code but keep getting errors across the board. Is my logic or Syntax flawed?

View 11 Replies View Related

Queries :: Conditional Formatting Query Results

Feb 4, 2014

how to conditionally format query results? I have read another forum post that says that query conditional formatting is possible.This database keeps track of projects and their associated tasks & statuses. I created different queries depending on task name( i.e. assignment date, approval date, etc.) Now, with some of the tasks, if it is overdue, it needs to be highlighted red. If it's cutting it close, should be yellow. I can't figure out how to set up a conditional formatting rule to address this. So instead I've had to create to separate queries for "red" and "yellow" rules, and display them separately in the Dashboard form.

View 4 Replies View Related

Queries :: Populating ComboBox Via Query With Conditional Criteria

Dec 23, 2014

I'm populating an unbound ComboBox with a Query via the QueryDesigner. The value of the Rowsource depends on the value of another ComboBox at the main Form.

After several hours of trial and error, I came to the solution showed at the attached image ("works"); my concern is.. why does my first approach does not work via the IIF clause? ("not work")...

View 2 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved