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

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 9235
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 NextToLastShiftDate
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*********@gmail.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...@snet.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 NextToLastShiftDate
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...@gmail.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*********@gmail.com>
wrote:
>On Jun 25, 11:01 am, Roy Harvey <roy_har...@snet.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 NextToLastShiftDate
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...@gmail.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
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...
3
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#...
2
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...
2
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...
3
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> ...
1
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...
10
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...
5
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',...
1
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...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.