Giorni della settimana

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Yachi

    Giorni della settimana

    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.

    Thanks!!!!
  • Erland Sommarskog

    #2
    Re: Giorni della settimana

    [posted and mailed]

    Yachi (yachi@pointel. it) writes:[color=blue]
    > 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.[/color]

    WHERE datepart(weekda y, 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
    SQL Server 2025 redefines what's possible for enterprise data. With developer-first features and integration with analytics and AI models, SQL Server 2025 accelerates AI innovation using the data you already have.

    Comment

    • Steve Kass

      #3
      Re: Giorni della settimana

      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,get date())+@@datef irst in (2, 5)

      -- Saturday and Sunday only
      where...
      and DATEPART(dw,get date())+@@datef irst in (1, 7)

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


      Yachi wrote:[color=blue]
      > 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.
      >
      > Thanks!!!![/color]

      Comment

      Working...