1

MS SQL に、開始日と終了日、時間、時刻を含む行のテーブルがあります。GETDATE がそれらの行の曜日と時刻に一致するテーブルから行を取得できる T-SQL クエリが必要です。具体的には、行に曜日/時間がある曜日に始まり、次の日に終わる場合にクエリが機能する必要があります。

私が取り組んでいる構造は次のとおりです。

_start_day_of_week (int) = 5
_start_hour (int) = 15
_start_minute (int) = 30
_end_day_of_week (int) = 6
_end_hour (int) = 2
_end_minute (int) = 30
_title (string) = 'My Sample Row'
_id (int) = 1

現在の DATETIME を指定して、この行を取得するにはどうすればよいですか?

4

3 に答える 3

0

次のようなものを試すことができます:

select * from [yourtable]
where yourdatefield between getDate() and (getDate()+1 )
于 2011-02-05T03:59:24.117 に答える
0

あなたの要件は少し現実的ではないように見えるので、まだ不明です。しかし、ここに行きます。

DECLARE @A AS TABLE(
_start_day_of_week int,
_start_hour int,
_start_minute int,
_end_day_of_week int,
_end_hour int,
_end_minute int,
_title varchar(10),
_id int 
)
--Above is temp table for example
INSERT @A
SELECT 5,15,30,6,2,30,'SAMPLE 1', 1 UNION ALL
SELECT 6,15,30,6,17,30,'SAMPLE 2', 2

DECLARE @month int = datepart(month,getdate())
DECLARE @currentDay int = datepart(dw,getdate())
DECLARE @currentHour int = datepart(hour, getdate())
DECLARE @currentMinute int = datepart(minute, getdate())



SELECT * FROM @A --Don't use select *. This is just an example.
WHERE --Where GETDATE matches
_start_day_of_week = @currentDay --The day of week
AND
_start_hour = @currentHour --and time of those rows
AND
_start_minute = @currentMinute
--I have not done any matching against the _end columns as
--your criteria are vague. Should it exclude all days except
--the current day and the currentday+1?
-- But you would use a similar method.
于 2011-02-05T15:20:29.090 に答える
0

datepart関数を使用して関数を使用できるはずですgetdate

http://msdn.microsoft.com/en-us/library/aa258265%28v=sql.80%29.aspx

于 2011-02-05T04:00:39.377 に答える