473,804 Members | 4,223 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

compare 2 values in same solumn

I am trying to compare the last two values in the same column of a
table. First of all, I have a column titled Row_Index that uses an
index which starts at 1 and increments by 1. What I am trying to do
is compare the values in the column 'Shift_Date' for the maximum value
of Row_Index and the (maximum value - 1) of Row_Index. I've been
trying to declare two strings, setting each string equal to one of my
values, and then comparing the strings. But this doesn't seam to be
working right. I'm not sure I am even declaring the strings
correctly. Does anyone know how I can do this. A sample of what one
of my values looks like in Shift_Date is ' 6/25/2007'.

Jun 25 '07 #1
3 9262
What exactly is the datatype of Shift_Date? What action are you
trying to take based on the comparison?

If you want to compare them inside a SELECT this might get you
started.

SELECT A.ShiftDate as LastShiftDate,
B.ShiftDate as NextToLastShift Date
FROM (SELECT * FROM TheTable
WHERE Row_Index =
(SELECT MAX(Row_Index) FROM TheTable) as A
CROSS JOIN
(SELECT * FROM TheTable
WHERE Row_Index =
(SELECT MAX(Row_Index)-1 FROM TheTable) as B

Roy Harvey
Beacon Falls, CT

On Mon, 25 Jun 2007 15:44:07 -0000, mcolson <mc*********@gm ail.com>
wrote:
>I am trying to compare the last two values in the same column of a
table. First of all, I have a column titled Row_Index that uses an
index which starts at 1 and increments by 1. What I am trying to do
is compare the values in the column 'Shift_Date' for the maximum value
of Row_Index and the (maximum value - 1) of Row_Index. I've been
trying to declare two strings, setting each string equal to one of my
values, and then comparing the strings. But this doesn't seam to be
working right. I'm not sure I am even declaring the strings
correctly. Does anyone know how I can do this. A sample of what one
of my values looks like in Shift_Date is ' 6/25/2007'.
Jun 25 '07 #2
On Jun 25, 11:01 am, Roy Harvey <roy_har...@sne t.netwrote:
What exactly is the datatype of Shift_Date? What action are you
trying to take based on the comparison?

If you want to compare them inside a SELECT this might get you
started.

SELECT A.ShiftDate as LastShiftDate,
B.ShiftDate as NextToLastShift Date
FROM (SELECT * FROM TheTable
WHERE Row_Index =
(SELECT MAX(Row_Index) FROM TheTable) as A
CROSS JOIN
(SELECT * FROM TheTable
WHERE Row_Index =
(SELECT MAX(Row_Index)-1 FROM TheTable) as B

Roy Harvey
Beacon Falls, CT

On Mon, 25 Jun 2007 15:44:07 -0000, mcolson <mcolson1...@gm ail.com>
wrote:
I am trying to compare the last two values in the same column of a
table. First of all, I have a column titled Row_Index that uses an
index which starts at 1 and increments by 1. What I am trying to do
is compare the values in the column 'Shift_Date' for the maximum value
of Row_Index and the (maximum value - 1) of Row_Index. I've been
trying to declare two strings, setting each string equal to one of my
values, and then comparing the strings. But this doesn't seam to be
working right. I'm not sure I am even declaring the strings
correctly. Does anyone know how I can do this. A sample of what one
of my values looks like in Shift_Date is ' 6/25/2007'.
When using the 'Last' function, do you have to have the columns sorted
by when they were entered?

Jun 25 '07 #3
>When using the 'Last' function, do you have to have the columns sorted
>by when they were entered?
What 'Last' function? I did not use any such function, and have not
heard of any such function.

MAX() is unrelated to order. SQL tables are not ordered anyway, any
order you need must be built into the data so that you can use ORDER
BY to control the order of the results when querying.

TOP is dependent on order (contolled using ORDER BY), but I did not
use TOP.

Roy Harvey
Beacon Falls, CT

On Mon, 25 Jun 2007 17:29:08 -0000, mcolson <mc*********@gm ail.com>
wrote:
>On Jun 25, 11:01 am, Roy Harvey <roy_har...@sne t.netwrote:
>What exactly is the datatype of Shift_Date? What action are you
trying to take based on the comparison?

If you want to compare them inside a SELECT this might get you
started.

SELECT A.ShiftDate as LastShiftDate,
B.ShiftDate as NextToLastShift Date
FROM (SELECT * FROM TheTable
WHERE Row_Index =
(SELECT MAX(Row_Index) FROM TheTable) as A
CROSS JOIN
(SELECT * FROM TheTable
WHERE Row_Index =
(SELECT MAX(Row_Index)-1 FROM TheTable) as B

Roy Harvey
Beacon Falls, CT

On Mon, 25 Jun 2007 15:44:07 -0000, mcolson <mcolson1...@gm ail.com>
wrote:
>I am trying to compare the last two values in the same column of a
table. First of all, I have a column titled Row_Index that uses an
index which starts at 1 and increments by 1. What I am trying to do
is compare the values in the column 'Shift_Date' for the maximum value
of Row_Index and the (maximum value - 1) of Row_Index. I've been
trying to declare two strings, setting each string equal to one of my
values, and then comparing the strings. But this doesn't seam to be
working right. I'm not sure I am even declaring the strings
correctly. Does anyone know how I can do this. A sample of what one
of my values looks like in Shift_Date is ' 6/25/2007'.

When using the 'Last' function, do you have to have the columns sorted
by when they were entered?
Jun 25 '07 #4

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

Similar topics

3
5878
by: Frank | last post by:
Hi! I'm kinda stuck here. I have an Hashtable with with my custom "Item" Object. The key used in the Hashtable is the "Item.Id", i have selected this key because with a lot of functions i can get the right object from the hashtable really fast. But now i need a function whom can get an object from the hashtable based on the values each "Item" object holds. ("Item.ColorId","Item.SizeId","Item.OtherId"), but i can't identify the object...
3
6608
by: Sukh | last post by:
Hi, I have two object of same class but I want to check if there is any value different b/w both object or not Is there any way... Obj1.Equals(obj2) is not working for this. Its in C# Thanks. Sukh
2
7972
by: nidsonline | last post by:
I've a page where I'm calling record from Database. Each record has an ID and a text box displayed on the page. When the user fills in the values of a text box, depending on the values of the text box i've to do some further work. For eg. I've to add two records if the textbox value of 2 records is same. I'll try to create an example here <-----this is from the DB-------> <-----this is form field---> ID Task Hrs ...
2
1480
by: sloan | last post by:
What is the most concise way to ...... bail out of a loop (or return false) if one value isn't the same as all the others in a collection? For example: I have an EmpCollection, which is a collection of Employee objects. Employee object has a .DeptID property (int)
3
6035
by: HelpPlzz | last post by:
I want to compare the min and max values between two dropdowns. This script sometimes gives correct result ...and sometimes not... Pls can u answer me whts goin wrong sometimes. <html> <head> <script type='text/JavaScript'> function validateBox() {
1
1110
by: metanarcissus | last post by:
"hi i have two excel spreadsheets (databases!) that have more than 8000 records in them. one is the old version (A) and one is the new version (B). the primary key (ID) is the name for all of these but the quantity for some of their lab results have been updated. i need to find a way to identify those records in the old database that have new column values for "Quantity". i'd appreciate any help. thanks. btw. i have imported the two...
10
2726
by: companion98 | last post by:
pls help.. (sh scripting) I have 3 files, file1 & file2 both have thousands of records of mobile numbers, while updatefile.txt is for the output. what i want to do is to compare the mobile field of file1 to file2, if the mobile number in file1 have been activated then the result appends to updatefile.txt while if the number is not yet activated then it will do nothing and will not displayed in updatefile.txt. (I have done similar to this, but...
5
7659
by: intosana | last post by:
Good day, I would appreciate your help with my question: I have an array: array(product_type, product_color, quantity); For example - I have got 3 items in this array: array('bmw', 'green', '4'); array('audi', 'red', '6'); array('bmw', 'green', '7');
1
2334
by: Rickard Hill | last post by:
I haven't been working very much with arrays before, do I'm pretty clueless of how to do this. Hope someone have the time to help out. I have the following code; <?php function check_system($sys) { $srvCount; $con = mysql_connect("localhost","username","passwd");
0
9706
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10577
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10332
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...
0
10077
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...
0
9150
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7620
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
6853
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
5521
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4299
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

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.