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

IF statements in queries???

Hi All,

It has been a while since I was last bothering you all!

I have just started a new job, and therefore the new challenge to delelop the systems!

Is it at all possible to calculate an if statement in a query?? At the moment we have serveral stores some which open on a sunday and some which dont.

If the store is open it'll have a figure, if not it'll just have a 0. Targets are generated for these stores by week rather than by day.

I need to apportion out the weekly figure into the days

The sort of calculation required is: If [Sunday] = 0, then 0. If [Sunday] >0 then [sunday] / [target]

Any ideas???


Many Thanks


Dan
Aug 25 '07 #1
3 1092
Scott Price
1,384 Expert 1GB
Hi All,

It has been a while since I was last bothering you all!

I have just started a new job, and therefore the new challenge to delelop the systems!

Is it at all possible to calculate an if statement in a query?? At the moment we have serveral stores some which open on a sunday and some which dont.

If the store is open it'll have a figure, if not it'll just have a 0. Targets are generated for these stores by week rather than by day.

I need to apportion out the weekly figure into the days

The sort of calculation required is: If [Sunday] = 0, then 0. If [Sunday] >0 then [sunday] / [target]

Any ideas???


Many Thanks


Dan

Good morning Dan,

You'll want to explore the iif() statement. It accepts three arguments separated by commas: the expression to be evaluated, the value returned if false, the value returned if true.

iif means, if and only if.

Regards,
Scott
Aug 25 '07 #2
Good morning Dan,

You'll want to explore the iif() statement. It accepts three arguments separated by commas: the expression to be evaluated, the value returned if false, the value returned if true.

iif means, if and only if.

Regards,
Scott
Thats great, thanks for that!


Dan
Aug 25 '07 #3
Scott Price
1,384 Expert 1GB
Thats great, thanks for that!


Dan

You're welcome, glad to help!

Regards,
Scott
Aug 25 '07 #4

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

Similar topics

0
by: David.Tymon | last post by:
>Description: MySQL v4.1.0-alpha only allows a client to prepare a maximum of 254 statements. On the 255th mysql_prepare() call, a failure is returned with no information returned by...
2
by: moosedeja | last post by:
I have an ASP (IIS 4.0) based website fronting a SQL Server 2000 database. I am trying to avoid using dynamic SQL for queries, and I am considering prepared statements as an alternative... All...
1
by: Tom D | last post by:
I'm rewriting a database interface that our company currently has. Currently it's using the Pear::DB interface, but we found that that was introducing a bit too much overhead. I'm rewriting the...
4
by: DG | last post by:
Hi, Can anyone advise how to execute multiple statements in a single query batch. For example- update customers set customer_name = 'Smith' where customer_name = 'Smyth'; select * from...
2
by: Annie D via AccessMonster.com | last post by:
Hi, Is it possible to use multiple statements in SQL?? (I’ve never used it before) : I have one query that i'm working with, The statements I want to use are as below, they all work...
2
by: saran | last post by:
I am having a problem with MySQL consuming a lot of memory and eventually throwing an Out of Memory error and restarting itself. The symptoms are that swap usage continues to rise until some...
4
by: christof | last post by:
I'm trying to run this T-SQL code using SqlCommand: USE master; ALTER DATABASE AdventureWorks SET SINGLE_USER; GO I did it like that: public static int ObtainExclusiveAccess(Server srv,...
2
by: ojorus | last post by:
Hi! Some questions regarding the mysqli-extension (php5) 1) Prepared statements: If I understand things right, prepared statements will give better performance if you make several similar...
7
by: paladin.rithe | last post by:
I have 2 statements that I'd like to string together in a query, but according to everything I'm seeing, it's not possible. What I'm doing is an insert of a row, where the primary key is an auto...
7
by: =?Utf-8?B?QVRT?= | last post by:
HOWTO Run multiple SQL statements from ASP/ADO to an Oracle 10g. Please help, I'm trying to write an ASP page to use ADO to run a long query against an Oracle 10g database, to create tables,...
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
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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...
1
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...
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,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.