I have a datetime column named Timesheet.StartTime and a datetime column
also named Employee.StartTime and I want to compare the time portion of each
to see if the Timesheet.StartTime is later than the Employee.StartTime. My
problem is that I only need to compare the time portion as the date on
Employee.StartTime is constant. Can anyone give me a tip or where I can
find a solution? Thanks.
DavidCan you give some example?|||Even if you need only time portions - assuming your date portions are
the same, all you need is the difference between the two dates.
Datediff function can exactly give you the difference in hours, mins or
sec. Hope this helps.
Have a look at the following code
declare @.date1 datetime,
@.date2 datetime
set @.date1 = '2006-02-14 13:40:07.603'
set @.date2 = '2006-02-14 15:40:07.603'
select datediff(hh,@.date1,@.date2)
select datediff(mi,@.date1,@.date2)|||Try using datepart() function. This can give you the exact part of the
datetime variable you are after.|||Use datediff
declare @.d1 datetime,
@.d2 datetime
set @.d1 = '2006-02-13 11:44:07.102'
set @.d2 = '2006-02-13 12:44:07.102'
select datediff(ss,@.d1,@.d2)
result is 3600
select datediff(ss,@.d2,@.d1)
result is -3600
so if first date is less than or equal to second date then result will
be >= 0 else it will be < 0
Regards
Amish Shahsql
Showing posts with label named. Show all posts
Showing posts with label named. Show all posts
Tuesday, March 27, 2012
Wednesday, March 21, 2012
Detecting Carriage Returns in a column
Can anyone provide me with some SQL that will identify rows from a table where a varchar column named "Notes" contain Carriage Returns?
I know that with report writer SQR I can translate CR's to white space but I do not know of any Sybase function that will allow me to do the same, any ideas on this well would be appreciated.For Microsoft SQL Server, I'd use CharIndex. For Sybase, it would depend on which of the Sybase servers you are using. Different Sybase engines have different string handling syntaxes.
-PatP|||Thanks Pat. One other dumb question is how is a Carriage Return represented in SQL? char[13]?? THanks again for your help, I used to know this but I'm a little rusty.|||That depends on what you mean by a carriage return. ;)
The problem is complex, because different operating systems store the "line end" marker differently, and because different SQL implementations have different ways of dealing with character expressions.
In Microsoft SQL Server, you represent a lone carriage return character asChar(13)...but, based on your previous question I think you really want to find a "line end" instead of a carriage return character. If you want to find a "line end" as used in Microsoft SQL Server, then you want:Char(13) + Char(10)
-PatP
I know that with report writer SQR I can translate CR's to white space but I do not know of any Sybase function that will allow me to do the same, any ideas on this well would be appreciated.For Microsoft SQL Server, I'd use CharIndex. For Sybase, it would depend on which of the Sybase servers you are using. Different Sybase engines have different string handling syntaxes.
-PatP|||Thanks Pat. One other dumb question is how is a Carriage Return represented in SQL? char[13]?? THanks again for your help, I used to know this but I'm a little rusty.|||That depends on what you mean by a carriage return. ;)
The problem is complex, because different operating systems store the "line end" marker differently, and because different SQL implementations have different ways of dealing with character expressions.
In Microsoft SQL Server, you represent a lone carriage return character asChar(13)...but, based on your previous question I think you really want to find a "line end" instead of a carriage return character. If you want to find a "line end" as used in Microsoft SQL Server, then you want:Char(13) + Char(10)
-PatP
Subscribe to:
Posts (Atom)