Need help with SQL query

Hello,

I am trying to build a SQL query that only count working days, I am able to make count all 365 days, but I only need specified working days.

Thanks,
ametradeAsked:
Who is Participating?
 
imitchieConnect With a Mentor Commented:
Hi ametrade,
What I mean is that DatePart depends on the @@datefirst setting, which can change depending on the OS regional/SQL Server setting.  using

WHERE ((DATEPART(DW, DateVar) + @@datefirst) % 7)  BETWEEN 2 AND 6

will make it work correctly for any setting and country
0
 
digital_thoughtsCommented:
Try this:

SELECT
      DateVar
FROM
      TableName
WHERE
      DATEPART(DW, DateVar) BETWEEN 2 AND 6


DATEPART with the argument "DW" returns a numeric value for the day of the week, 1 being Sunday and 7 being Saturday...
0
 
ametradeAuthor Commented:
digital_thoughts I am testing it, will let you know, thx.
0
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 
imitchieCommented:
to be more precise

SELECT DateVar
FROM TableName
WHERE ((DATEPART(DW, DateVar) + @@datefirst) % 7)  BETWEEN 2 AND 6

check BOL for @@datefirst
0
 
ursangelCommented:
DATEPART(DW, DateVar) BETWEEN 2 AND 6
this alone will pick up the dates for all the working days, unless otherwise its a specific holiday.
0
 
imitchieCommented:
ametrade: it's worth your while reading up on DatePart and @@datefirst, if your solution is for more than one small customer in one specific country
0
 
ametradeAuthor Commented:
Hi imitchie sorry for not specifying that, this is for Venezuela, thank you.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.