473,405 Members | 2,373 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,405 software developers and data experts.

Sum Query reports invalid procedure call

the query is as follow and is based on a big table called WeldData.

There are 2 materials being welded and each material can have different sizes.

so i have to pick the smallest size, unfortunately the diameter field is in text (ie one enters it like 2"), so i have to take running sum of the filtered values to derive at the Total.

Please help me where is the error ??

Many Thanks in Advance.

Posted below is the copy of the query.
Expand|Select|Wrap|Line Numbers
  1. SELECT sum(final)*3.14*25.4 AS new
  2. FROM (SELECT [Weld Type], [DWR Date], [Weld Flag], IIf(CSng(left([Material Diameter 1],(instr(1,[Material Diameter 1],"""",1)-1)))<CSng(left([Material Diameter 2],(instr(1,[Material Diameter 2],"""",1)-1))),CSng(left([Material Diameter 1],(instr(1,[Material Diameter 1],"""",1)-1))),CSng(left([Material Diameter 2],(instr(1,[Material Diameter 2],"""",1)-1)))) AS Final FROM WeldData GROUP BY [Weld Type], [DWR Date], [Weld Flag], IIf(CSng(left([Material Diameter 1],(instr(1,[Material Diameter 1],"""",1)-1)))<CSng(left([Material Diameter 2],(instr(1,[Material Diameter 2],"""",1)-1))),CSng(left([Material Diameter 1],(instr(1,[Material Diameter 1],"""",1)-1))),CSng(left([Material Diameter 2],(instr(1,[Material Diameter 2],"""",1)-1)))))  AS a
  3. WHERE [Weld Type] Like '*B*' And (Month([DWR Date])=Month(Now())-1) And ([Weld Flag] like "Production Joint" or [Weld Flag] like "New Joint" or [Weld Flag] like "Tracer Joint");
Feb 20 '09 #1
6 2715
DonRayner
489 Expert 256MB
I moved your Conversion from string to number and if statements out to a public Function.

Expand|Select|Wrap|Line Numbers
  1. Public Function MaterialSize(Material1 As String, Material2 As String) As Integer
  2. Material1 = Left(Material1, InStr(1, Material1, """", 1) - 1)
  3. Material2 = Left(Material2, InStr(1, Material2, """", 1) - 1)
  4.  
  5. If Material1 < Material2 Then
  6.     MaterialSize = Material1
  7. Else
  8.     MaterialSize = Material2
  9. End If
  10.  
  11. End Function
And Changing your SQL to this

Expand|Select|Wrap|Line Numbers
  1. SELECT sum(final)*3.14*25.4 AS new
  2. FROM (SELECT [Weld Type], [DWR Date], [Weld Flag], MaterialSize([Material Diameter 1],[Material Diameter 2]) AS Final FROM WeldData GROUP BY [Weld Type], [DWR Date], [Weld Flag], MaterialSize([Material Diameter 1],[Material Diameter 2])) AS a
  3. WHERE [Weld Type] Like '*B*' And (Month([DWR Date])=Month(Now())-1) And ([Weld Flag] like "Production Joint" or [Weld Flag] like "New Joint" or [Weld Flag] like "Tracer Joint"); 
Feb 21 '09 #2
It is a much better solution.

Many Thanks !! DonRayner
Feb 21 '09 #3
DonRayner
489 Expert 256MB
You're quite welcome. Good luck with your project.
Feb 21 '09 #4
NeoPa
32,556 Expert Mod 16PB
FYI: I would change your WHERE clause as follows too :
Expand|Select|Wrap|Line Numbers
  1. WHERE ([Weld Type] Like '*B*')
  2.   AND (Month([DWR Date])=Month(Date())-1)
  3.   AND ([Weld Flag] In('Production Joint', 'New Joint', 'Tracer Joint');
The effect will be the same, but it's tidier and more flexible.
Feb 22 '09 #5
Many Thanks for the advice. it is cleaner code.
Feb 23 '09 #6
NeoPa
32,556 Expert Mod 16PB
My pleasure.

Welcome to Bytes!
Feb 23 '09 #7

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

Similar topics

1
by: john | last post by:
Ran Windows update tonight. Since then I get this error: HTTP 500.100 - Internal Server Error - ASP error Internet Information Services ...
6
by: mork | last post by:
I am so frustrated - any help is appreciated. When trying to use common functions like Left and/or Mid I get the following error: Run-time Error '5': Invalid Procedure Call or Argument In my...
6
by: Martin Lacoste | last post by:
Ok, before I headbutt the computer... don't know why when I add criteria in a query, I get an 'invalid procedure call'. I also don't know why after searching the help in access, the various access...
2
by: Zoury | last post by:
Hi there! I'm using a COM component from my C# application and I can't get it to work properly. I get a COMException (Invalid procedure call or argument) on this line : //***...
1
by: Terry | last post by:
Hi. We had a in-house program that use a PRINTLBL.EXE to print label in DOS mode. after the label was printed, Window XP will issue the error message ( Invalid procedure call or arguments ). But if...
5
by: Matt | last post by:
I am receiving the following error from the simple script below. This works fine from a .NET form but when I access the dll from a Classic ASP page it fails. Microsoft VBScript runtime error...
5
by: Eric | last post by:
I run a program which read emails from a text file. There is some thing invalid in one or more text file. When program is busy doing parsing it shows that error and process stop. I dont know which...
6
by: HaggardSmurf | last post by:
Private Sub Downloader1_DownloadComplete(MaxBytes As Long, SaveFile As String) If MsgBox("Donwnload Finished. Would you like to install now?", vbInformation + vbYesNo, "Blue Cherry Media...
13
by: sasasasa | last post by:
Hi, I am getting the error saying 'Invalid Procedure Call' in my query. My query is very simple. I am just getting data from another query which is getting data from a table. SELECT ...
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
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...
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...
0
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...
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...

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.