473,666 Members | 2,237 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Converting Access qrys with logical expressions

I'm upsizing an Access database. Got the data converted, working on
the front end, converting queries to views, but having trouble
converting queries that use logical expressions like the following:
SELECT OrderId,
Sum((BackOrderQ tyAvailable>0)*-1) AS ReadyBackOrderI tems
FROM OrderDetails
INNER JOIN Items
ON (OrderDetails.C lientId = Items.ClientId)
AND (OrderDetails.I temId = Items.ItemId)
WHERE (NOT (SitesCustomerT ypeId = 2
AND ExpressBackorde r =True
AND OrderUrgency = 1 ))
GROUP BY OrderId;

Can someone suggest a strategy to achieve the same result, ie
OrderId,ReadBac kOrderItems that I can use in further joins?

Thanks in anticipation
Terry Bell
Jul 20 '05 #1
5 2293

"Terry Bell" <dr**********@h otmail.com> wrote in message
news:92******** *************** **@posting.goog le.com...
I'm upsizing an Access database. Got the data converted, working on
the front end, converting queries to views, but having trouble
converting queries that use logical expressions like the following:
SELECT OrderId,
Sum((BackOrderQ tyAvailable>0)*-1) AS ReadyBackOrderI tems
FROM OrderDetails
INNER JOIN Items
ON (OrderDetails.C lientId = Items.ClientId)
AND (OrderDetails.I temId = Items.ItemId)
WHERE (NOT (SitesCustomerT ypeId = 2
AND ExpressBackorde r =True
AND OrderUrgency = 1 ))
GROUP BY OrderId;

Can someone suggest a strategy to achieve the same result, ie
OrderId,ReadBac kOrderItems that I can use in further joins?

Thanks in anticipation
Terry Bell


Are you asking how to rewrite the SUM expression? I don't know exactly what
the syntax above means, so this is a guess:

sum(case when BackOrderQtyAva ilable > 0 then BackOrderQtyAva ilable else 0
end * -1)

If this is wrong, then I suggest you post CREATE TABLE and INSERT statements
to create your tables and populate some sample data, along with the result
you expect to see from your query.

Simon
Jul 20 '05 #2
"Simon Hayes" <sq*@hayes.ch > wrote in message news:<41******* ***@news.bluewi n.ch>...
"Terry Bell" <dr**********@h otmail.com> wrote in message
news:92******** *************** **@posting.goog le.com...
I'm upsizing an Access database. Got the data converted, working on
the front end, converting queries to views, but having trouble
converting queries that use logical expressions like the following:
SELECT OrderId,
Sum((BackOrderQ tyAvailable>0)*-1) AS ReadyBackOrderI tems
FROM OrderDetails
INNER JOIN Items
ON (OrderDetails.C lientId = Items.ClientId)
AND (OrderDetails.I temId = Items.ItemId)
WHERE (NOT (SitesCustomerT ypeId = 2
AND ExpressBackorde r =True
AND OrderUrgency = 1 ))
GROUP BY OrderId;

Can someone suggest a strategy to achieve the same result, ie
OrderId,ReadBac kOrderItems that I can use in further joins?

Thanks in anticipation
Terry Bell


Are you asking how to rewrite the SUM expression? I don't know exactly what
the syntax above means, so this is a guess:

sum(case when BackOrderQtyAva ilable > 0 then BackOrderQtyAva ilable else 0
end * -1)

If this is wrong, then I suggest you post CREATE TABLE and INSERT statements
to create your tables and populate some sample data, along with the result
you expect to see from your query.

Simon


Thanks very much Simon you have given me the direction I needed.
For the record, here's my full converted code - with some side errors
fixed

SELECT Q845Undelivered OrderDetails.Or derId, SUM(CASE WHEN
BackOrderQtyAva ilable > 0 THEN 1 ELSE 0 END) AS ReadyBackOrderI tems
FROM Q845Undelivered OrderDetails INNER JOIN
Items ON (Q845Undelivere dOrderDetails.C lientId =
Items.ClientId) AND (Q845Undelivere dOrderDetails.I temId =
Items.ItemId)
WHERE (NOT (SitesCustomerT ypeId = 2 AND ExpressBackorde r = 1 AND
OrderUrgency = 1))
GROUP BY Q845Undelivered OrderDetails.Or derId;
So:
Sum((BackOrderQ tyAvailable>0)*-1) AS ReadyBackOrderI tems ... in Access
SQL
becomes
SUM(CASE WHEN BackOrderQtyAva ilable > 0 THEN 1 ELSE 0 END) AS
ReadyBackOrderI tems ... in SQL

I also note that in Access you can say something like

WHERE IsBackOrder

and it evaluates IsBackOrder as a logical expression
whereas in sql server we need to say

WHERE IsBackorder = 1

Is that right?

Then I guess I need to think about NULL too ...

Also I notice in the query analyser it comes up with a message saying
it can't understand the CASE statement, but I can ignore that, can I,
as it seems to go ahead and execute the query anyway?

Once again thanks a million this has saved me lots of time

Terry Bell
Jul 20 '05 #3
<snip>
I also note that in Access you can say something like

WHERE IsBackOrder

and it evaluates IsBackOrder as a logical expression
whereas in sql server we need to say

WHERE IsBackorder = 1

Is that right?
Not quite - there is no Boolean data type in MSSQL, so how to evaluate
'true' or 'false' depends on the data type you've chosen. One common
solution is to use the bit data type, with 1 for true and 0 for false, in
which case your code above is correct (assuming true = 1).

Then I guess I need to think about NULL too ...
Yes - this is one reason why you often see requests for DDL (CREATE TABLE
etc.), as this makes it clear which columns allow NULL and which don't.
Something that seems to work fine may fail when NULLs are involved, so you
need to code for them if the data model allows them.

Also I notice in the query analyser it comes up with a message saying
it can't understand the CASE statement, but I can ignore that, can I,
as it seems to go ahead and execute the query anyway?
I have no idea without seeing the full error, but perhaps this is error 8153
"Warning: Null value is eliminated by an aggregate or other SET operation."?
If so, it's just a warning that the column you SUMmed on contains NULL data.

Once again thanks a million this has saved me lots of time

Terry Bell


You're welcome.

Simon
Jul 20 '05 #4
Generally just copy and paste from Access to Query Analyser. Check the
query runs correctly and then add CREATE PROCEDURE blah blah to the top
and run. This turns the script in to a stored procedure and loads it in
to the current database.

You might want to move all the restrictions to the WHERE clause other
wise you can get some interesting results if you are not very careful.

Sum((BackOrderQ tyAvailable)* -1)

(BackOrderQtyAv ailable > 0)
Adrian

Terry Bell wrote:
I'm upsizing an Access database. Got the data converted, working on
the front end, converting queries to views, but having trouble
converting queries that use logical expressions like the following:
SELECT OrderId,
Sum((BackOrderQ tyAvailable>0)*-1) AS ReadyBackOrderI tems
FROM OrderDetails
INNER JOIN Items
ON (OrderDetails.C lientId = Items.ClientId)
AND (OrderDetails.I temId = Items.ItemId)
WHERE (NOT (SitesCustomerT ypeId = 2
AND ExpressBackorde r =True
AND OrderUrgency = 1 ))
GROUP BY OrderId;

Can someone suggest a strategy to achieve the same result, ie
OrderId,ReadBac kOrderItems that I can use in further joins?

Thanks in anticipation
Terry Bell

Jul 20 '05 #5
On Thu, 16 Sep 2004 17:27:35 +0200, Simon Hayes wrote:
"Terry Bell" <dr**********@h otmail.com> wrote:

Also I notice in the query analyser it comes up with a message saying
it can't understand the CASE statement, but I can ignore that, can I,
as it seems to go ahead and execute the query anyway?


I have no idea without seeing the full error, but perhaps this is error 8153
"Warning: Null value is eliminated by an aggregate or other SET operation."?
If so, it's just a warning that the column you SUMmed on contains NULL data.


I don't think it's a null error -- I think he was editing his query in MS
Access's query editor, in an ADP file, rather than using SQL Server's Query
Analyzer. I've gotten that error from MS Access myself.

As Terry said, Access goes ahead and executes it anyway. It just can't
parse it properly to represent it in the graphical query editor.
Jul 20 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
1369
by: Arnold Shore | last post by:
How do I do that? This is for some bit-diddling, but the logical functions like AND require numeric expressions, per the book. AS
0
2319
by: jwa6 | last post by:
We have recently went to access 2003 from access 97. And from word 97 to Word 2003. We have an Access application we use for ms word mail mergers to a 5160 mail label format. The data for the Access mdb is linked to an Oracle db thru ODBC. There are 2 access union qrys that we use to get the correct field for the labels. Going thru the 'mail merge' wizard in MS word - we no longer see those union qrys. (no union qry shows on the word...
80
35089
by: Christopher Benson-Manica | last post by:
Of course one can get the effect with appropriate use of existing operators, but a ^^ operator would make for nice symmetry (as well as useful to me in something I'm working on). Am I the only one who would find it useful? -- Christopher Benson-Manica | I *should* know what I'm talking about - if I ataru(at)cyberspace.org | don't, I need to know. Flames welcome.
7
1315
by: Ryan Epinos | last post by:
How would i convert this on vb.net? Open DestinFile For Input As #25 If LOF(25) > 0 Then Close() GoTo AllreadyE End If
23
2639
by: Reggie | last post by:
Hi and TIA. I developed several A2K dbs which are now being run on my clients computer which have been upgraded to Access 03. I'm not sure exactly what they mean but of you know or could point me in a direction to find info on how to prevent and/or fix the db's so that these message don't pop up when the app is started. Error messages below: 1. Microsoft Jet 4.0 service pack 8 must be installed to block unsafe expressions without...
9
3742
by: marko | last post by:
/* code start */ int a = 0; /* expected evaluation and excution order with precedence in mind /* False(3) , True(1), False(2) */ if ( (a=1) == 0 || 0 != 1 && (a =2) == 1) putchar('T'); printf("%d", a); /* code end */ 2
2
4484
by: deltaa5 | last post by:
Hi. i need a source code compute logical expressions in lex/yacc. for Example: (20>5) or (6<=6)--->true (1<=2) and (3==1) --->false.
1
1074
by: =?Utf-8?B?VW5kZXJTZXZlbg==?= | last post by:
Two questions, Can a param. qry take a varaible passed to it from VB as the param and if so how, if not what is a good work around? Second, can a module be used to call an update qry? I've noticed on events seem unable to call update qrys, but I want to use on events to update tables. Thanks
1
1403
by: don.fleming | last post by:
We have a tool built for determing which Access version an mdb is that works nicely. Problem is, hundreds of PC's here are getting reimaged without it(!) Since I've been unable to solve that problem, am quite interested in this. Can an Access 97 be harmed by opening it with the Access 2003 app as a User of the mdb.? We have LOTS of this happening here and I'm starting to research if/how much of a problem this is. If the Users have no...
0
8781
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8550
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8638
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6191
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5662
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4365
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2769
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2006
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1769
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.