Groups | Blog | Home
all groups > sql server (alternate) > august 2003 >

sql server (alternate) : Giorni della settimana



Yachi
8/20/2003 1:17:48 PM
devo passare all'SQL una stringa where che mi applichi delle modifiche
in un range di data ma soltanto il martedi e il venerdì per esempio,
opppure soltanto il giovedì e la domenica: Riporto un esempio:

......
......
......
WHERE DATA BETWEEN 'Datainizio' AND 'DataFine' AND
...............................

come gli passo dopo l'AND i giorni della settimana?
In VB posso distinguere i giorni con Weekbday ma mi serve un consiglio
per completare la clausola where.

Erland Sommarskog
8/21/2003 10:00:20 PM
[posted and mailed]

Yachi (yachi@pointel.it) writes:
[quoted text, click to view]

WHERE datepart(weekday, data) BETWEEN 3 AND 4

Il result di datepart depende a SET DATEFIRST. Il default per us_english
è 7, che voule dire il result per giovedì è 5.


--
Erland Sommarskog, SQL Server MVP, sommar@algonet.se

Books Online for SQL Server SP3 at
Steve Kass
9/13/2003 4:54:39 PM
You can use DATEPART to determine the day of the week.
It is best to use @@datefirst in the query, in case
its value changes.

-- Monday and Thursday only
where...
and DATEPART(dw,getdate())+@@datefirst in (2, 5)

-- Saturday and Sunday only
where...
and DATEPART(dw,getdate())+@@datefirst in (1, 7)

-- Steve Kass
-- Drew University
-- Ref: C64FDB90-0033-436B-A3BB-FC338FAB382A


[quoted text, click to view]
AddThis Social Bookmark Button