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

Maximum value of 2 columns in the third

hi everybody,

i have a question which may be rather trivial to some of you:

in my scenario i have three columns with col 1 and 2 holding integers
and i want to know the respective maximum for each row in col 3.

i´ve been using something with max(...) but it works only for 1
parameter. i want to use only sql, no further vb... would be great if
someone could help.... thx!
Yours, Kenny Ajram

Jan 15 '07 #1
4 6368

kenny wrote:
hi everybody,

i have a question which may be rather trivial to some of you:

in my scenario i have three columns with col 1 and 2 holding integers
and i want to know the respective maximum for each row in col 3.

i´ve been using something with max(...) but it works only for 1
parameter. i want to use only sql, no further vb... would be great if
someone could help.... thx!
Yours, Kenny Ajram
Kenny,
storing this is bad design. Use a query instead. And MAX works on a
single field, and not really across fields. You can use IIF to do
this. Something like...

SELECT tblA.FieldA, tblA.FieldB,
IIF(Nz([fieldA],0)>=Nz([FieldB],0),Nz([FieldA]),Nz([FieldB])) As
MaxTest
FROM tblA
....

Jan 16 '07 #2
kenny wrote:
>i have a question which may be rather trivial to some of you:

in my scenario i have three columns with col 1 and 2 holding integers
and i want to know the respective maximum for each row in col 3.

i´ve been using something with max(...) but it works only for 1
parameter. i want to use only sql, no further vb... would be great if
someone could help.... thx!

The fields in a table are supposed to be dependent on
**only** the primary key. If you can compare two fields in
the same table, there is likely to be a normalization flaw
in your table design.

The Max (and all other aggregate) functions operate on a
single field in all of the records so you are on the wrong
track. To find the larger of two values use:
IIf(a b, a, b)
If you need to do this for more than two values, I strongly
suggest that you create a public function (in a standard VBA
module), instead of coming up with ever increasingly complex
expressions.

--
Marsh
Jan 16 '07 #3
thank you so far, but the problem still remains. the code is pretty
much what i want, but i get a syntax error, saying i should put the
expression in brackets... i´m sure i have used the right syntax... i
ceated a third field and used the "build" menu entry to create the
query....

SELECT tblA.FieldA, tblA.FieldB,
IIF(Nz([fieldA],0)>=Nz([FieldB],0),Nz([FieldA]),Nz([FieldB])) FROM tblA

i also used

SELECT tblA.FieldA, tblA.FieldB,
IIF([fieldA]>=[FieldB]),[FieldA],[FieldB]) FROM tblA
the same error.... :-((

Jan 22 '07 #4
it´s done, thx for your help :-)))

Jan 23 '07 #5

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

Similar topics

3
by: Dave Crypto | last post by:
Hi There, SUMMARY: I need to know what the actual maximum date limit possible on a row of a MYSQL database. MORE DETAILS: For example, does a MYSQL database only allow 4032 bytes of data...
1
by: Alex Satrapa | last post by:
I have a table from which I'm trying to extract certain information. For historical reasons, we archive every action on a particular thing ('thing' is identified, funnily enough, by 'id'). So the...
2
by: Kums | last post by:
What is the maximum permissible size of a database? Is there any limitation. What is the maximum # of tablespace's allowed in a database? Thanks for your response.
8
by: Fred L. Kleinschmidt | last post by:
I need to know the largets value representable in a variable. However, I do not know the variable's true type - only that it is some kind of int. It may be any of the following: #typedef Newtype...
1
by: Luis Esteban Valencia | last post by:
Hello. I have a datagird with textboxes on a column item template, I also have 2 other columns that are hidden and I want to retrieve his value. But I havent found how to do it. Thanks very much...
1
by: msnews.microsoft.com | last post by:
Hi Every Body, I have tow columns in the database, the third columns the division of both columns. The first two columns are both of type decimal, when the third columns get value its type is...
0
by: John | last post by:
Hi, I have set a DataGridViewComboBoxColumn for a complex object type, and set the DisplayMember and ValueMember to members of the object type. My problem is how to programmatically set the cell...
6
by: nidhisahay | last post by:
i have one table which has 10 columns. all having integer values. and only 1 row. how can i get the maximum value from amongst the columns in that row.
6
by: =?Utf-8?B?U2hhcm9u?= | last post by:
I'm using the VScrollBar and set it as follow: m_vScrollBar.Minimum = -19602; m_vScrollBar.Maximum = 0; m_vScrollBar.SmallChange = 1; m_vScrollBar.LargeChange = 1089; m_vScrollBar.Value =...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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
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...

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.