Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > SQL Server > SQL Server 2000 > SQL Server 2000
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
SQL Server 2000 General discussion of Microsoft SQL Server -- for topics that don't fit in one of the more specific SQL Server forums. version 2000 only. There's a new forum for SQL Server 2005.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the SQL Server 2000 section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old July 10th, 2006, 07:37 AM
Friend of Wrox
Points: 686, Level: 9
Points: 686, Level: 9 Points: 686, Level: 9 Points: 686, Level: 9
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2005
Location: Kolkata, West Bengal, India.
Posts: 128
Thanks: 0
Thanked 0 Times in 0 Posts
Default query to find Saturday/Sundays

Hi,
I want to find the count of all the Saturdays & Sundays in a month as well as within a date range 01/07/2006 - 31/08/2006


Can this be done with the help of SQL query.???

Pls help
Reply With Quote
  #2 (permalink)  
Old July 10th, 2006, 07:49 AM
Authorized User
 
Join Date: Sep 2005
Location: , , .
Posts: 95
Thanks: 0
Thanked 0 Times in 0 Posts
Default

One way

select count(*)
from table
where DateColumn between '20060701' and '20060831'
and datepart(dw,DateColumn) in (1,7)

------------------------------------------ http://sqlservercode.blogspot.com/
Reply With Quote
  #3 (permalink)  
Old July 10th, 2006, 08:01 AM
Friend of Wrox
Points: 686, Level: 9
Points: 686, Level: 9 Points: 686, Level: 9 Points: 686, Level: 9
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2005
Location: Kolkata, West Bengal, India.
Posts: 128
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi,
Thanks for your help but I do not have any table to store the datas for all the days in a month.What would be the query for system date..

Arnab
Reply With Quote
  #4 (permalink)  
Old July 10th, 2006, 08:35 AM
Friend of Wrox
Points: 686, Level: 9
Points: 686, Level: 9 Points: 686, Level: 9 Points: 686, Level: 9
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2005
Location: Kolkata, West Bengal, India.
Posts: 128
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi,
Also date range is stored in 2 columns startdate and enddate now can the query be formed...Pls help I'm in a soup.
Reply With Quote
  #5 (permalink)  
Old July 10th, 2006, 08:37 AM
Friend of Wrox
Points: 686, Level: 9
Points: 686, Level: 9 Points: 686, Level: 9 Points: 686, Level: 9
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2005
Location: Kolkata, West Bengal, India.
Posts: 128
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi,
I ran the query but it did not return any result.
pls can anyone help.
Reply With Quote
  #6 (permalink)  
Old July 10th, 2006, 01:22 PM
Friend of Wrox
 
Join Date: May 2006
Location: Helsingborg, , Sweden.
Posts: 246
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I have written an article about this at http://www.sqlservercentral.com/colu...tiliretire.asp

Also see this topic http://p2p.wrox.com/topic.asp?TOPIC_ID=46835
Reply With Quote
  #7 (permalink)  
Old July 11th, 2006, 02:17 AM
Friend of Wrox
Points: 686, Level: 9
Points: 686, Level: 9 Points: 686, Level: 9 Points: 686, Level: 9
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2005
Location: Kolkata, West Bengal, India.
Posts: 128
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks Peso for your great help!!!!
Reply With Quote
  #8 (permalink)  
Old July 15th, 2006, 12:44 AM
Friend of Wrox
 
Join Date: Aug 2004
Location: Orange County, CA, USA.
Posts: 385
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I prefer to do this with a table that contains dates. You populate it with one row for every day in the date range your dealing with. Thus a simple query using a count and a where >= x date and <= y date and dayofweek = ??? you get your results.

Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
get the coming saturday date of a given date amlesh SQL Server 2000 10 August 17th, 2007 09:20 AM
getting the second saturday of every month haleem .NET Framework 2.0 1 May 3rd, 2007 12:38 AM
Find String in query vishwadh SQL Server ASP 3 September 6th, 2006 03:16 AM
No. of Saturday/Sunday arnabghosh SQL Server ASP 1 August 31st, 2006 11:32 AM
SQL query to find key when auto-increment SandyFeder SQL Server ASP 1 November 21st, 2005 09:49 AM



All times are GMT -4. The time now is 09:26 AM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.