How To Compare Dates From A Dif Row And Column

Dec 13, 2006

sorry i posted this in the tsql forum by accident, here's a repost

I've got a query that I need help with. This is a simplified version of the table I have.

sellerID, orderID, time1, time2, time3, time4
1, 1b1, 11:30 11:35 11:40 11:45
1, 1b2, 11:50 11:55 12:00 12:05
1, 1b3, 12:10 12:15 12:20 12:25
2, 1c1, 11:20 11:25 11:30 11:35
2, 1c2, .... and so on

What I want is a datediff between time4 of the first OrderID to time1 of the next orderID within the same sellerID.

What I want is the following output

sellerID, orderID, timeDif1(time4-time1 of nextrow), timeDif2(time2-time1), TimeDif3(time3-time2), timeDif4(Time4-time3)

1, 1b1, 10mins, 5mins, 5mins, 5mins

Any help would be appreciated!!
THanks

View 1 Replies


ADVERTISEMENT

Compare Two Dates

Dec 14, 2006

I need to compare tow dates DateField1 and DateField2 and find number of hours between these two dates. Then I need to deduct non-business days and hours (Business days: Monday-Friday and Business Hours: 7:00am-7:00pm) from this and find net hours. How can I do this?

View 7 Replies View Related

How Do I Compare Dates?

Apr 13, 2008

Hi,I need to compare Todays Date with a Date in the Table (DateExpired)to see if the membership expired. How do I do that?   thanks 
SELECT  DateExpired  FROM Member

View 2 Replies View Related

How To Compare Dates

Feb 4, 2002

how to compare the dtaes for the follwing

SELECT COL1,COL2 FROM TABLE1
WHERE WORKDATE >01/01/2002

THE WORKDATE IN THE TABLE IS HAVING DATETIME DATATYPE.
I DONT WANT CONSIDER THE TIME OF THE DATEPART.
I JUST WANT TO COMPARE THE DD-MM-YYYY.

PLEASE HELP ME IN THAT.
THANKS IN ADVANCE

View 1 Replies View Related

Compare Dates

Apr 9, 2007

Hi,

I am new to SQL and I have a problem to deal with dates.
I have a field called LogDate (smalldatetime) and default value getdate(). The date is added immediately when a visitor visits a page of my site.

The problem is that I cannot retrieve the no of the visitors for today using getdate(). I use the following query but I am sure that something missing.

SELECT Count(*) As DailyVisitors
FROM stats
WHERE LogDate = CONVERT(varchar(10), GETDATE(), 103)

Please help

Denis

www.tabletennis.gr

View 9 Replies View Related

How Do I Compare Dates In Sql Server?

Jun 23, 2006

Hi,
I wanted to display the createDate provided by the asp membership table.
my where clause is this .. WHERE CreateDate = GetDate()
I have create an account today but when i run my select statement with this where clause, the result doesnt show up. It seem like they compare the time as well. How can i make the GetDate to compare only the dates but not the time?
 
 

View 1 Replies View Related

Compare Dates String And Int

Jul 5, 2007

need to look through hundreds of rows and compare two columns, and pull out rows where the date difference is 7 days

problem is one column stores the date as a string and values in that column look like this:

01/12/2007 10:15 pm
or
01/12/2007

the other column stores the date as seconds since 1/1/1970, which is good and easy to work with..

how do I write the select?
any ideas
thnx
tony

View 3 Replies View Related

Expression - Compare Dates

Jul 5, 2007

How can I check if:



Date1 is newer than Date2?



Thank you!

View 5 Replies View Related

Compare Dates In The Same Record

Jan 9, 2008



I need to compare several dates in a single record and determine the maximum value. Not sure how to do this in TSQL. Something like this (though I obviously can't use the MAX function because):

SELECT MAX(datefield1,datefield2,datefield3) as latestchange,jobnum
FROM table1



Anyone have a function that will do this? Or is there one built in?

Thanks!
Brian

View 11 Replies View Related

Stored Procedure To Compare Dates

Mar 20, 2008

Hi:

Well, I am venturing into new territory for me. I'm very illiterate when it comes to SQL Server and so I need assistance. I have the beginnings of my stored procedure, which is supposed to compare two dates/times and If they are not equal I need to kick off a DTS Package.

So, here's what I have so far (it returns two dates like I would expect):

CREATE PROCEDURE usrCompareDataDownload
AS
BEGIN
SELECT MAX(ASP_ZZ_CHNG_TMST) FROM tbl_MaterialWeeklyData;
SELECT MAX(ZZ_CHNG_TMST) FROM TV_ASP_DPUL_WKLY;

END
GO


Thanks,

Bob Larson

View 5 Replies View Related

Transact SQL :: How To Compare More Than Two Dates In Server

Oct 10, 2015

I have three date columns startdate,enddate,rmd

I need to write a query like get all the rows by comparing rmd with system todaydate and these must be with in startdate and enddate

id startdate enddate rmd
1  10-oct-15   16-oct-15    11-oct-15
2   11-oct-15    14-oct-15     11-oct-15
3   09-oct-15     11-oct-15      10-oct-15
4   07-oct-15      08-ot-15        07-oct-15
5
if sysdate(today) is 11-oct-15 then i need to get all the rows of 1, 2,3

View 5 Replies View Related

Compare Dates And Fail Job If No Match

Feb 15, 2007

This is probably a problem with a pretty simple solution but i can't find the right control/data flow item to handle it

Scenario.

I determine the database date for my source data for a set of ETL jobs via a piece of SQL - this gets passed to a master package variable which is subsequently to be used as the "Load date" of the resulting child package ETL routines. However I only want the packages to run if the LoadDate has either not been run before or is the next one in the DW sequence.

To check for this, In my data warehouse I also have a table called Import_Registry where the date of each upload is stored at the end of the daily ETL routines. So I can obtain the potential NextUpload date via this bit of SQL script.

SELECT DATEADD(day, 1, MAX(Upload_Date)) AS NextUpload FROM Import_Registry

Problem. I need to compare these two dates (the source db date & the DW next upload date) to see if they match. If they do match, then I run all the ETL packages using the date. If they do not match, say for example if the source database date is less than the "NextUpload" date I want to exit the routines "gracefully" and log the failure.

How do I get this working - can't seem to get my head around how I can compare the 2 dates ?

View 5 Replies View Related

Transact SQL :: Pull Dates From Database And Then Compare

Jun 10, 2015

I need to pull dates from a DB2 database via TSQL (Linked server - IBM DB2 for i IBMDASQL OLE DB Provider) and compare it to today for a less than or greater than type comparison.

Database: DB2, Customer information housed here
Columns:
UTOFMM - Month (2 character, numeric)
UTOFDD - Day (2 character, numeric)
UTOFYY - Year (2 character, numeric. Problem: years from 2000 to 2009 are stored as 0, 1, 2, ... etc)
UTOFCV - Century Value (2 char, numeric.  0 = before 2000, 1 = in or after 2000)

I need to concatenate the date to be "sql" friendly, and then compare to today's date.  It's to find any customer with date values in the fields above, and then differentiate between dates before today and after today.Here is the snippet of what I'm trying to fix.  This portion of a nightly job is just checking for <u>any</u> value in the UTOFMM column of the current record.

Add Customer ID
Update [responder].[Temp_RX_CUSTOMERS]
set CustomerID = lf.UTCSID
from [responder].[Temp_RX_CUSTOMERS] LEFT Outer Join
[HTEDTA].[THOR].[HTEDTA].UT210AP lf ON [responder].[Temp_RX_CUSTOMERS].LocationID = lf.UTLCID
where lf.UTOFMM = 0
GO

View 4 Replies View Related

SQL Server 2012 :: Compare Dates Between 2 Different Rows And Columns?

Feb 18, 2015

What I need to be able to find is any records where the Discontinue_Date is greater than the Effective_Date on the next row for a given Customer ID and Part_ID. This is a customer pricing table so the Discontinue_Date of row 53 for example should never be greater than the Effective_Date of row 54130, these are the records I'm looking to find. So I'm looking for a SELECT query that would look for any records where this is true. Obviously the last Discontinue_Date row for a Customer_ID will not have a next row so I wouldn't want to return that.

View 9 Replies View Related

SQL Server 2008 :: Compare Dates In Rows Of A Table?

Apr 8, 2015

I have the following information in a table. What I would like to do is pull out all the visits for each customer that are less than 30 days apart.

Customer# VisitDate
9082012-07-28 00:00:00.000
9082013-09-20 00:00:00.000
9082013-12-23 00:00:00.000
9082014-01-10 00:00:00.000
9082014-01-27 00:00:00.000
9082014-02-16 00:00:00.000
9082014-05-21 00:00:00.000
9082014-05-30 00:00:00.000
9082014-10-01 00:00:00.000
9082015-02-28 00:00:00.000
9082015-03-22 00:00:00.000
9272012-02-16 00:00:00.000
9272014-12-14 00:00:00.000
9272014-12-23 00:00:00.000

View 2 Replies View Related

SQL Server 2008 :: Compare Data / Loop Through Dates And Insert Into Table

Sep 21, 2015

I have three tables:

"PaymentsLog"
"DatePeriod"
"PaidOrders"

As per below

SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[PaymentsLog](

[Code] ....

Is there a way to look at the DatePeriod table and use the StartDtae and EndDate as the periods to be used in the select statement and then cursor through each date between these two dates and then insert the data in to the PaymentsLog table?

View 3 Replies View Related

SQL Compare Column In Table

Aug 15, 2006

I have table with the following structure :
ID Result1 Reusult2 NewResult1 NewResult2 FinalResult
-1----10------6-----------7------------9----
-2----32------16----------32-----------16---
-3----12------2-----------1------------9----
-4----50------6-----------9------------7----
-5----90------9-----------90-----------9----
-6----18------2-----------3------------2----


My problem :

I want to compare each record in column Result1 and NewResult1,Result2 and NewResult2
Such as my above table :
With ID=2 and ID=5 : I need to update column "Final Result" with value equal 1 ,otherwise any records with value equal zero.
Conclusion :
If ((Result1=NewResult1) and (Result2=NewResult2)) --> Final Result =1
else
Other Records -->Final Result=0
How to write sql statement ?
Thank you very much !

View 5 Replies View Related

Matrix : Compare Column Value

Mar 16, 2008

Hi,

I am a newbie with Reporting services and I have a question about matrix using...
So I am using SSRS on an cube with MDX language. I have a matrix like that :


C1 C2 C3
---------------------------
R1 | 10 12 09
R2 | 08 10 23

So I would like to color my best values on a same row. I don't find a function in the expression editor.....

Do you have an idea ?????

View 8 Replies View Related

Compare Values In A Column

Feb 17, 2008

I have a table with one column. The values can be Y or N. How do I compare the 2 values and return a result depending on the comparison. For example, if I my column data looks like this.

Y
N

I need to compare them and if they match return a specific value and if they are different return a specific value.

View 12 Replies View Related

Compare Two Columns And Update The Third Column

May 21, 2008

 Hi,I have three columns and want to update the third column based on the comparison of first two columns in the same table.For instance:Col1 - val1, val2, val3, val4, val5......Col2 - NULL, NULL, val1, NULL, val2....Col3 - TRUE, TRUE, FALSE, FALSE, FALSE....Thanks for any help.

View 4 Replies View Related

Compare 2 Piece Of String In A Column

May 30, 2008

Hi All,
I have a column in my table like so:
'D4B00 L2A00 L3A00 L6C00 P1C00 L2A28 P4B00 '
How do I check in SQL if any pieces have the first 3 character the same.  In the above case, L2A is present twice.  I need to do this because I need display disctinct items, therefore L2A needs to be displayed only once.
Any help is appreciated.
Thanks

View 3 Replies View Related

How To Select A Column To Compare Two Values In It

Apr 24, 2015

How to select a column to compare two values in it with AND

Select distinct c.reg#, a.fname, a.lname, to_char(b.L#) as "L"
from employee a, driver b, trip c
where a.e#=b.e#
and b.l#=c.l#
and (c.reg#='PKR3344'AND c.reg#='WWF1155')
order by c.reg#;

error no rows selected..I want c.reg# for the two values inclusive

View 4 Replies View Related

Help...!! Can We Compare Alias Of Column Within The Same Query??

Feb 22, 2007

Can We Compare alias of column(Derived column) within the same query??

Ex:

Select (abc+50)*100 as 'WXY' from XYZ where WXY>150

.....

I cant execute such statement ... Can anyone help me how to comapre the alias within the same query..?

View 3 Replies View Related

How To Compare Image/varbinary Column

May 5, 2008

what is the best way of comparing image/varbinary and nullable column in sql server?
this is what i do to find out the different in image column in 2 tables sharing the same structure:
Select *
From TblA s
Left Join TblB c On

s.Id = c.Id And Coalesce(Convert(VARBINARY(MAX), c.Image),'') <> Coalesce(Convert(VARBINARY(MAX), s.Image),'')
Where c.Id IS NULL

alternatively, i was thinking to compare the column with the size, but worry about the accuracy:
Select *
From TblA s
Left Join TblB c On

s.Id = c.Id And ISNULL(Datalength(c.Image),0) <> ISNULL(Datalength(s.Image),0) Where c.Id IS NULL

any suggestion/advise will be appreciated ~

View 11 Replies View Related

Compare Rows To Determine If Column Values Are Different?

Mar 2, 2011

I need to determine if a value for a group of rows is the same or different and I am not sure where to begin. I am fairly new to writing T-Sql code. I am working with SQL Server 2005. This is a work assignment; I am not a student.

I have two tables: One for Course and another for CourseDays. As the Course table implies, it lists courses for a school. The CourseDays tables has a row for each day a course is held. For instance, one course maybe held on Monday, Wednesday, and Friday, so there would be three rows, one row for each day. A given course could be held in a different room for each day. I am trying to write a query that returns one row for each course, and if the room number is the same for each day the class is held, return that room number in the row, else return 'Various'.

Course table:
CourseID, Desc
1 English
2 History
3 Science

CourseDays table:
CourseID, Day, RoomID
1 M 320
1 W 445
1 F 680
2 T 123
2 Th 123
3 M 514
3 T 514
3 W 521
3 Th 901
3 F 521

Expected results:
CourseID, Desc, RoomID
1 English Various
2 History 123
3 Science Various

I simplified the example, as there are about 30 columns in the table and about half a million rows.

View 14 Replies View Related

T-SQL (SS2K8) :: Compare Multiple Column Between Two Tables

Aug 14, 2014

I want to display records from @table1 only when combination of col2,col3 and col4 are present in @table2.In Below case I want output as: below two records only.

'test1', 'need this record', 25, {d '1901-01-01'}
'test3', 'some longer value', 23, {d '1900-01-01'}
declare @table1 table (
col1 varchar(10) not null,
col2 varchar(200) null,
col3 int not null,

[code]....

View 2 Replies View Related

SQL Server 2008 :: How To Compare The Date Column

Mar 30, 2015

I need to compare the date column. The date column is 2012-01-22 in this format.

So I need to convert getdate() into this format yyyy-mm-dd.

What is the style number I have to use?

I used the link [URL] but I didn't see this format.

View 5 Replies View Related

SQL Server 2012 :: Compare Column In Two Tables?

Apr 20, 2015

i have two tables.

Table A
IdName
101Dante
102Henry
103Harold
104Arnold

Table B
NumberName
102Dante
107Gilbert
109Harold
110Arnold
106Susan
112Marian

I want the result in table 3 like below, if value exists in Table A and not exists in Table B then the record should enter in table 3 with table name in new column, and vice versa.

Table C
Col1Col2
HenryTable A
Gilbert Table B
Susan Table B
Marian Table B

using below logic to get the values from tables..

select
t1.columnA
, t2.*
from
table1 t1
join table2 t2 on t2.columnB = t1.columnA

View 9 Replies View Related

Column Compare In Same Table And Show Only Changed Value

Aug 18, 2014

How can I compare column in the same table and show only column and value that has been changed.

declare @t table (GroupID CHAR(6),Text1 VARCHAR(MAX),Text2 VARCHAR(MAX),Text3 VARCHAR(MAX))

insert into @t
SELECT '11111','Text1','Text2','Text3'

insert into @t
SELECT '11111','Text1','Text2','Text4'

END RESULTS:

Column Name Old New
Column 3 |'Text3' |'Text4'

View 9 Replies View Related

Compare Two Column Values With Leading Zeros

Jul 20, 2005

Hey,This is what I would like to do:===========Declare @chvBOLNumberSet @chvBOLNumber='0001234'Select * from BOL where BOLNumber=@chvBOLNumberI want to return the row/rows when BOLNumber=1234============The problem is the leading zeros. @chvBOLNumber can be 01234 or 001234 or ...Hope the above makes sense. How can I do this ? (probably using wildcards)Thanks, John

View 2 Replies View Related

Reporting Services :: Compare Different Column Rows Value

May 18, 2015

I need to fill the cell background color in the Matrix Table SSRS report based on below requirement -

When
For A resource 'Capacity' equals to 'WorkExcludingCapacityAndAvailbility' and Project Status equals to OPEN then GREEN
When
For A resource 'Capacity' equals to 'WorkExcludingCapacityAndAvailbility' and Project Status equals to PENDING then RED

Here is the below mock-up data -

Looking for solution based on above mockup data how I can compare different rows value by resource considering Project Status Column value in Matrix Table report to set the background color.

View 3 Replies View Related

Compare Column Names From Two Tables In Same Database

May 17, 2008

I'm not a full-time DBA, so excuse my style of expressing my question.I have a database which has 2 tables in SQL 2005. Both these tables have similar column names, EXCEPT for new extra columns in FY2007_DATA. I can visually see the difference in columns in Database Diagrams. My goal is to :- I want to compare FY2007 tbl column names to FY2006 column names and display only those columns as results that do not match.Tbl 1 :- FY2006_DATA Tbl 2:-



FY2007_DATA

With online reading and help I have managed to get this script to do exactly opposite of what i want. Below is the query

/* This query compares the column names from two tables and displays the ones that have an exact match. It does not care for case-sensitiveness */

Select a.Table_Name, a.Column_Name, (b.Table_Name), (b.column_name)
From [2006-2011].INFORMATION_SCHEMA.Columns AS a
Join [2006-2011].INFORMATION_SCHEMA.Columns AS b on a.Column_Name = b.Column_Name
Where a.TABLE_NAME = 'FY2006_DATA'
And b.TABLE_NAME = 'FY2007_DATA'
AND a.Column_Name IN
(Select Column_Name = LEFT(c.column_name, 20) FROM
[H1B_2006-2011].INFORMATION_SCHEMA.Columns AS c WHERE c.TABLE_NAME = 'FY2007_DATA' )


When I change "AND a.Column_Name IN.." to "AND a.Column_Name NOT IN.." so that the results will (should) display the extra columns in FY2007, in fact I do not see any results, but query executes perfect.

How can I achieve my goal.?

Thank you

View 1 Replies View Related

Difference Between Dates In The Same Column

Jun 23, 2007

i was working on a appication and just got stuck with this.
I have a column on a table which is a date column and i need to get the days differenct and copy it in another column
e.g

date days between
27-02-2005 1
28-02-2005 0
28-02-2005 0
28-02-2005 1
01-03-2005 0
01-03-2005

View 4 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved