Click here to Skip to main content
15,906,335 members
Home / Discussions / Database
   

Database

 
Questionsql Pin
Thanusree Duth4-Jul-10 23:02
Thanusree Duth4-Jul-10 23:02 
AnswerRe: sql Pin
J4amieC4-Jul-10 23:58
J4amieC4-Jul-10 23:58 
GeneralRe: sql Pin
R. Giskard Reventlov5-Jul-10 0:22
R. Giskard Reventlov5-Jul-10 0:22 
GeneralRe: sql Pin
J4amieC5-Jul-10 0:41
J4amieC5-Jul-10 0:41 
GeneralRe: sql Pin
Mycroft Holmes5-Jul-10 0:48
professionalMycroft Holmes5-Jul-10 0:48 
AnswerRe: sql Pin
R. Giskard Reventlov5-Jul-10 0:04
R. Giskard Reventlov5-Jul-10 0:04 
QuestionSQL FUNCTION USING DATE TIME Pin
Thanusree Duth4-Jul-10 22:10
Thanusree Duth4-Jul-10 22:10 
AnswerRe: SQL FUNCTION USING DATE TIME Pin
J4amieC4-Jul-10 23:56
J4amieC4-Jul-10 23:56 
MIN and MAX are indeed the right functions to use, however, for them to work properly the data must be stored in a DATETIME field, because using strings to store those times will obviously yield string-based results for min & max. There is no way to calculate the min and max times from strings representing dates.

Secondly, in order ot know that 12:15am is after 7:10pm you must also store the date date part along with the time part.

Here is a simple test script that shows the process (and returns the results you want). You'll notice ive used yesterdays date for the 3 values before midnight, and today's date for the one after midnight.

WITH data(firstTimeIn,lastTimeOut )
AS
(
	SELECT CAST('4 july 2010 7:10:09:000PM' AS DATETIME),CAST('4 july 2010 9:40:45:000PM' AS DATETIME)
	UNION 
	SELECT CAST('4 july 2010 10:20:32:000PM' AS DATETIME),CAST('5 july 2010 12:15:27:000AM' AS DATETIME)
)
SELECT 
	MIN(firstTimeIn) as firstTimeIn,
	MAX(lastTimeOut) as lastTimeOut 
FROM data


Result:
firstTimeIn: 2010-07-04 19:10:09.000
lastTimeOut: 2010-07-05 00:15:27.000
GeneralRe: SQL FUNCTION USING DATE TIME Pin
JasonShort5-Jul-10 6:10
JasonShort5-Jul-10 6:10 
GeneralRe: SQL FUNCTION USING DATE TIME Pin
J4amieC5-Jul-10 6:30
J4amieC5-Jul-10 6:30 
Questionstored procedure Pin
Thanusree Duth4-Jul-10 18:47
Thanusree Duth4-Jul-10 18:47 
AnswerRe: stored procedure Pin
Mycroft Holmes4-Jul-10 19:09
professionalMycroft Holmes4-Jul-10 19:09 
QuestionLinked Server Pin
John.L.Ponratnam4-Jul-10 16:49
John.L.Ponratnam4-Jul-10 16:49 
QuestionDynamic SQL and the Crystal Report Pin
indian1433-Jul-10 19:10
indian1433-Jul-10 19:10 
AnswerRe: Dynamic SQL and the Crystal Report Pin
Mycroft Holmes3-Jul-10 20:38
professionalMycroft Holmes3-Jul-10 20:38 
QuestionI want to know that which is better to save a graph either XAML or SQL databse. Pin
hotthoughtguy2-Jul-10 20:59
hotthoughtguy2-Jul-10 20:59 
AnswerRe: I want to know that which is better to save a graph either XAML or SQL databse. Pin
Mycroft Holmes2-Jul-10 22:39
professionalMycroft Holmes2-Jul-10 22:39 
QuestionComplicated size calculation Pin
Member 34269362-Jul-10 5:35
Member 34269362-Jul-10 5:35 
AnswerRe: Complicated size calculation Pin
Mycroft Holmes2-Jul-10 11:43
professionalMycroft Holmes2-Jul-10 11:43 
QuestionHello Pin
gertag2-Jul-10 1:08
gertag2-Jul-10 1:08 
AnswerRe: Hello Pin
Mycroft Holmes2-Jul-10 1:53
professionalMycroft Holmes2-Jul-10 1:53 
QuestionJoining columns from two tables into one column Pin
RossouwDB1-Jul-10 22:05
RossouwDB1-Jul-10 22:05 
AnswerRe: Joining columns from two tables into one column Pin
David Skelly1-Jul-10 22:32
David Skelly1-Jul-10 22:32 
AnswerRe: Joining columns from two tables into one column Pin
Mycroft Holmes1-Jul-10 22:43
professionalMycroft Holmes1-Jul-10 22:43 
GeneralRe: Joining columns from two tables into one column Pin
RossouwDB1-Jul-10 22:54
RossouwDB1-Jul-10 22:54 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.