Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
skillile
Posting Yak Master
208 Posts |
Posted - 2001-12-21 : 10:50:17
|
| I have two columns a start and and end time.I first need to parse the table and check for the minutevalue 0, 15, 30. This will set my @minutevalue either on the hour, quarter or halfThen upon getting the correct minute value I need to get the timedifference based on @minutevalueso if:starttime=8:30endtime=9:30@minutevalue= half hourdifferece=2same example setting the @minutevalue on the quarterdifference = 4I have played with the case and if exists to get the @minutevaluebut am looking for any suggestions to tie this together.below is my two fields they are both smalldatetime.starttime endtime ----------------------- ------------------- 2001-12-17 06:00:00 2001-12-17 07:00:002001-12-17 08:00:00 2001-12-17 09:00:002001-12-17 14:00:00 2001-12-17 10:00:002001-12-17 08:00:00 2001-12-17 09:00:002001-12-17 10:00:00 2001-12-17 11:00:002001-12-17 09:00:00 2001-12-17 10:00:002001-12-17 13:00:00 2001-12-17 14:00:002001-12-17 11:00:00 2001-12-17 12:00:00THANKS as always in advance |
|
|
AjarnMark
SQL Slashing Gunting Master
3246 Posts |
Posted - 2001-12-21 : 12:41:55
|
Try something like this...declare @MinuteFlag int, @Difference floatSELECT @Difference = datediff(mi, '12/21/2001 10:00:00', '12/21/2001 11:30:00')SELECT @MinuteFlag = datepart(mi, '12/21/2001 10:15:00')If @MinuteFlag = 0 BEGIN SET @MinuteFlag = 60ENDSELECT @Difference / @MinuteFlag -------------------It's a SQL thing... |
 |
|
|
tribune
Posting Yak Master
105 Posts |
Posted - 2001-12-21 : 12:57:41
|
| DECLARE @StartTime datetimeDECLARE @EndTime datetimeDECLARE @MinuteValue intDECLARE @Difference intSELECT @StartTime = '2001-12-17 06:00:00'SELECT @EndTime = '2001-12-17 07:30:00'SELECT @MinuteValue = DateDiff(minute,@StartTime,DateAdd(minute,DatePart(minute,@EndTime),@StartTime))SELECT @Difference = DateDiff(minute,@StartTime,@EndTime) / (CASE @MinuteValue WHEN 0 THEN 60 ELSE @MinuteValue END)PRINT @MinuteValuePRINT @Difference |
 |
|
|
barmalej
Starting Member
40 Posts |
Posted - 2001-12-21 : 14:08:50
|
| Try this. First of all this SELECT checks your @minutevalue against Starttime and calculates then.SELECT 'Start'=starttime , 'End'=endtime,'Result'=DATEDIFF(mi, starttime, endtime) / COALESCE(NULLIF(DATEPART (mi, starttime), 0), 60) FROM YourTableORDER BY starttime , endtime--------------If you need check against both Starttime and Endtime you may for example UNION both tables and then take MAX() value grouping by starttime, endtime. Something:SELECT max(tmp.result)FROM (SELECT .... --Against StarttimeUNIONSELECT ... -- Against Endtime) tmpGROUP BY tmp.Starttime, tmp.EndtimeORDER BY tmp.Starttime, tmp.EndtimeThere are other ways also as you need MAX of the two valuesHope this will help |
 |
|
|
skillile
Posting Yak Master
208 Posts |
Posted - 2001-12-21 : 14:13:52
|
| thanks everybody, i am playing with all solutionsto find the best way. I think you've given me enoughto get there.:)slow down to move faster... |
 |
|
|
tribune
Posting Yak Master
105 Posts |
Posted - 2001-12-21 : 15:32:05
|
| pick me pick memine is more efficient :P |
 |
|
|
|
|
|
|
|