Wrox Programmer Forums
Go Back   Wrox Programmer Forums > SQL Server > SQL Server 2000 > SQL Server 2000
|
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 software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old July 10th, 2006, 07:37 AM
Friend of Wrox
 
Join Date: Apr 2005
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
 
Old July 10th, 2006, 07:49 AM
Authorized User
 
Join Date: Sep 2005
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/
 
Old July 10th, 2006, 08:01 AM
Friend of Wrox
 
Join Date: Apr 2005
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
 
Old July 10th, 2006, 08:35 AM
Friend of Wrox
 
Join Date: Apr 2005
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.
 
Old July 10th, 2006, 08:37 AM
Friend of Wrox
 
Join Date: Apr 2005
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.
 
Old July 10th, 2006, 01:22 PM
Friend of Wrox
 
Join Date: May 2006
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
 
Old July 11th, 2006, 02:17 AM
Friend of Wrox
 
Join Date: Apr 2005
Posts: 128
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks Peso for your great help!!!!
 
Old July 15th, 2006, 12:44 AM
Friend of Wrox
 
Join Date: Aug 2004
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.






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 10:49 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.