I have a table with many fields ( 10 fields out of which 6 are for specific product issues). Each of those 6 has a number enter in it via a form.I've created a report and dont need to display these 6 fields. Instead i would like to display the maximum number entered in the fields in a group of records ( as i would sum records based on the persons name and date). I need to display only
eg..
Name vial , stopper , seals , codes , other
Joe 2 5 7 3 5
I would like to display "Seals" in the report as it is the highest number when all of Joe's records are summed.
How would i do that? Please Help ..
6 1251
I have a table with many fields ( 10 fields out of which 6 are for specific product issues). Each of those 6 has a number enter in it via a form.I've created a report and dont need to display these 6 fields. Instead i would like to display the maximum number entered in the fields in a group of records ( as i would sum records based on the persons name and date). I need to display only
eg..
Name vial , stopper , seals , codes , other
Joe 2 5 7 3 5
I would like to display "Seals" in the report as it is the highest number when all of Joe's records are summed.
How would i do that? Please Help ..
Try this ... -
SELECT Name, Max([vial]) As MaxVial,
-
Max([stopper]) As MaxStopper, Max([seals]) As MaxSeals,
-
Max([codes]) As MaxCodes, Max([other]) As MaxOther
-
FROM TableName
-
GROUP BY Name;
-
Mary
NeoPa 32,556
Expert Mod 16PB
I would like to display "Seals" in the report as it is the highest number when all of Joe's records are summed.
I tried doing this with multiple IIf() function calls and, though it is possible, it gets very complex very quickly, as more fields are added to the equation.
Instead I wrote a quick function in VBA (needs to be put in a general module or, if only required in the one report, it can be in the code for that report. - 'MaxVal Returns the string associated with the maximum value passed
-
'Parameters are passed in pairs,
-
'the first being the value and the second the associated string.
-
Public Function MaxVal(ByVal lngVal As Long, _
-
ByVal strAssoc As String, _
-
ParamArray avarArgs() As Variant) As String
-
Dim intIdx As Integer
-
-
intIdx = LBound(avarArgs)
-
If (UBound(avarArgs) - intIdx) Mod 2 <> 0 Then Stop
-
MaxVal = strAssoc
-
For intIdx = intIdx To UBound(avarArgs) Step 2
-
If avarArgs(intIdx) > lngVal Then
-
lngVal = avarArgs(intIdx)
-
MaxVal = avarArgs(intIdx + 1)
-
End If
-
Next intIdx
-
End Function
The SQL to use it is :
[code]SELECT Name, MaxVal([vial],'Vial',
[stopper],'Stopper',
[seals],'Seals', - ,'Code',
-
[other],'Other')
-
FROM TableName
NeoPa 32,556
Expert Mod 16PB
Just noticed it is ALSO grouped by name.
Will post fixed version shortly.
NeoPa 32,556
Expert Mod 16PB
Simply change the SQL to :
[code]SELECT [Name], MaxVal(Max([vial]),'Vial',
Max([stopper]),'Stopper',
Max([seals]),'Seals',
Max( - ),'Code',
-
Max([other]),'Other')
-
FROM TableName
-
GROUP BY [name]
If the word "Vial" is not actually required but the value instead, that is easier but I'm going from your question. If I'm wrong then I can change it quite quickly.
Nice piece of code Adrian. I think I'll rob it.
Mary
NeoPa 32,556
Expert Mod 16PB
I like my code to be plagiarised (else why would I be here).
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Stephan |
last post by:
Hi,
I'm using Visual Studio 2003 (C#) with the integrated
Crystal Report software and have the following question:
How can I assign a value (string) to an unbound (string)
field in Crystal...
|
by: Danny J. Lesandrini |
last post by:
First, this is _not_ a question about how to get Crystal Reports to run
on a client machine. I've got all the merge modules added to the project
and it's working fine. The question is about...
|
by: CSDunn |
last post by:
Hello,
I have a situation with MS Access 2000 in which I need to display report
data in spreadsheet orientation (much like a datasheet view for a form). If
you think of the report in terms of what...
|
by: Tom |
last post by:
This is related to an earlier post entitled "Text in Query/Numbers in
Report"
Brief recap - report has a query as a record source. The query shows
the correct data, the report translating the...
|
by: Danny J. Lesandrini |
last post by:
Didn't get any takers on this post this morning at dotnet.General, so I'm
reposting here.
First, this is _not_ a question about how to get Crystal Reports to run
on a client machine. I've got...
|
by: Kaur |
last post by:
Hi,
I am trying to create a crosstab type of report without using crosstab
query. The report captures several survey questions and for each survey
questions there are multiple choices that...
|
by: Stinky Pete |
last post by:
Evening,
I have a form that uses 5 pages (it's an electronic copy of the paper
version) we are going to use for manufacturing non conformances and
product deviations. In case your wondering,...
|
by: itmags |
last post by:
I need to create a couple of reports, invoices, credit reports, etc...
My question is: How/what is the best way to go about this using
VB2005 / SQL Server 2000
Crystal Reports? MS Reporting?...
|
by: lorirobn |
last post by:
Hi,
I have a report displaying items that are missing from a room. I
created 2 queries, the first getting the items IN the room, and the
second being an "unmatched" query that references the...
|
by: JessicaZ |
last post by:
Hi everyone! I'm new here and have a question regarding Leban's report to pdf tool. I am working on a database where we are using this code to send a report out to pdf(duh) BUT what I need to do is...
|
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
|
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...
|
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...
|
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,...
|
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,...
|
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: 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...
|
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,...
|
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...
| |