Quick Search for:  in language:    
Full,Calendar,each,Month,Year,Just,pass,integ
   Code/Articles » |  Newest/Best » |  Community » |  Jobs » |  Other » |  Goto » | 
CategoriesSearch Newest CodeCoding ContestCode of the DayAsk A ProJobsUpload
SQL Stats

 Code: 44,501. lines
 Jobs: 115. postings

 How to support the site

 
Sponsored by:

 
You are in:
 

Does your code think in ink?
Login





Latest Code Ticker for SQL
Group Data Values
By Thivya Prabakaran on 11/29


Grouping Data
By Thivya Prabakaran on 11/29


Separating Function
By Jayanthi Venugopal on 11/27


Filter duplicate records from a table
By Geoff Kazzi on 11/25


qStats_Ex
By Ewald Hofman on 11/19


find depended objects
By chandra sekhar on 11/19


Click here to put this ticker on your site!


Add this ticker to your desktop!


Daily Code Email
To join the 'Code of the Day' Mailing List click here!

Affiliate Sites



 
 
   

SQL CALENDAR

Print
Email
 
VB icon
Submitted on: 9/20/2002 3:01:38 PM
By: John Overton  
Level: Advanced
User Rating: By 10 Users
Compatibility:SQL Server 2000, SQL Server 7.0, SQL Server 6.5 and earlier

Users have accessed this code 6027 times.
 
(About the author)
 
     UPDATED:Produces Full Calendar for each Month in a Year. Just pass year as an integer. Let me know if it proves useful. Call it Like: Execute Calendar 2002
 
code:
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
 
Terms of Agreement:   
By using this code, you agree to the following terms...   
1) You may use this code in your own programs (and may compile it into a program and distribute it in compiled format for languages that allow it) freely and with no charge.   
2) You MAY NOT redistribute this code (for example to a web site) without written permission from the original author. Failure to do so is a violation of copyright laws.   
3) You may link to this code from another website, but ONLY if it is not wrapped in a frame. 
4) You will abide by any additional copyright restrictions which the author may have placed in the code or code's description.

--**************************************
--     
-- Name: SQL CALENDAR
-- Description:UPDATED:Produces Full Cal
--     endar for each Month in a Year. Just pas

-- s year as an integer. Let me know if it -- proves useful. Call it Like: EXECUTE Calendar 2002 -- By: John Overton -- -- Inputs:@year(int) -- -- Returns:Calendar for each month -- --This code is copyrighted and has-- limited warranties.Please see http:// -- www.Planet-Source-Code.com/vb/scripts/Sh -- owCode.asp?txtCodeId=546&lngWId;=5--for details.--************************************** -- --************************************** -- -- -- Name: SQL CALENDAR -- Description:Produces Full Calendar fo -- -- r each Month in a Year. Just pass yea -- r a -- s an integer. Let me know if it prove -- s u -- seful. -- By: John Overton -- -- Inputs:@year(int) -- -- Returns:Calendar for each month -- --This code is copyrighted and has-- lim -- ited warranties.Please see http:// -- www.Planet-Source-Code.com/xq/ASP/txt -- Cod -- eId.546/lngWId.5/qx/vb/scripts/ShowCo -- de. -- htm--for details.--****************** -- ******************** -- SET QUOTED_IDENTIFIER OFF GO SET ANSI_NULLS ON GO CREATE PROCEDURE CALENDAR (@YEAR INT) AS DECLARE @INPUTDATE DATETIME DECLARE @DATE DATETIME DECLARE @LASTDATE DATETIME DECLARE @MONTHDAYCOUNT INT DECLARE @COUNT INT DECLARE @DAY VARCHAR(10) DECLARE @STARTWEEK INT DECLARE @CURWEEK INT DECLARE @STARTMONTH INT SET @INPUTDATE='01/01/' + CAST(@YEAR AS CHAR(4)) PRINT @INPUTDATE SET @STARTMONTH=1 WHILE @STARTMONTH<=12 BEGIN SET @COUNT=1 SET @DATE = DATEADD(d, -(DATEPART(dd, @INPUTDATE) - 1), @INPUTDATE) SET @LASTDATE=DATEADD(DD,-1,DATEADD(MM,1,@DATE)) SET @MONTHDAYCOUNT=datediff(d, @date, dateadd(m, 1, @date)) SET @STARTWEEK=DATENAME(WEEK,@DATE) DECLARE @CURRWEEK INT DECLARE @CUR INT CREATE TABLE #TEMP( WEEK VARCHAR(10), SUNDAY VARCHAR(10), MONDAY VARCHAR(10), TUESDAY VARCHAR(10), WEDNESDAY VARCHAR(10), THURSDAY VARCHAR(10), FRIDAY VARCHAR(10), SATURDAY VARCHAR(10)) DECLARE @wkcount int DECLARE @weeksinmonth int DECLARE @EXEC NVARCHAR(2000) SET @WKCOUNT=1 SET @weeksinmonth=datediff(week, @date, @lastdate) + 1 WHILE @wkcount<= @weeksinmonth begin INSERT INTO #TEMP VALUES(@wkcount,'SUNDAY', 'MONDAY', 'TUESDAY', 'WEDNESDAY', 'THURSDAY', 'FRIDAY', 'SATURDAY') SET @WKCOUNT=@WKCOUNT + 1 end
WHILE @COUNT<=@MONTHDAYCOUNT BEGIN SET @DAY=DATENAME(WEEKDAY,@DATE) IF @STARTWEEK=DATENAME(WEEK,@DATE) SET @CURRWEEK=1 ELSE BEGIN SET @CUR=DATENAME(WEEK,@DATE) SET @CURRWEEK=(@CUR-@STARTWEEK)+1 END SET @EXEC='UPDATE #TEMP SET ' + @DAY + ' =' + CAST(@COUNT AS CHAR(2)) + ' WHERE WEEK=' + CAST(@CURRWEEK AS CHAR(2))+ 'AND WEEK IS NOT NULL' EXEC SP_EXECUTESQL @EXEC SET @DATE=DATEADD(DD,1,@DATE) SET @COUNT=@COUNT + 1 END
UPDATE #TEMP SET SUNDAY=' ' WHERE SUNDAY='SUNDAY' UPDATE #TEMP SET MONDAY=' ' WHERE MONDAY='MONDAY' UPDATE #TEMP SET TUESDAY=' ' WHERE TUESDAY='TUESDAY' UPDATE #TEMP SET WEDNESDAY=' ' WHERE WEDNESDAY='WEDNESDAY' UPDATE #TEMP SET THURSDAY=' ' WHERE THURSDAY='THURSDAY' UPDATE #TEMP SET FRIDAY=' ' WHERE FRIDAY='FRIDAY' UPDATE #TEMP SET SATURDAY=' ' WHERE SATURDAY='SATURDAY' SELECT SUNDAY, MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, SATURDAY FROM #TEMP DROP TABLE #TEMP SET @INPUTDATE=DATEADD(MM,1,@INPUTDATE) SET @STARTMONTH=@STARTMONTH+1 END
GO SET QUOTED_IDENTIFIER OFF GO SET ANSI_NULLS ON GO


Other 5 submission(s) by this author

 

 
Report Bad Submission
Use this form to notify us if this entry should be deleted (i.e contains no code, is a virus, etc.).
Reason:
 
Your Vote!

What do you think of this code(in the Advanced category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor See Voting Log
 
Other User Comments
9/21/2002 11:49:50 AM:Markus Q
Procedure only returns a single month 
(January).  You may want to have it 
take two parameters, a month and year. 
Good work though.
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
9/22/2002 4:16:12 AM:
I would like to get a code that can be 
used to grade the students marks in VB 
6.0 and also how to inter-Link diffrent 
forms 
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
9/22/2002 12:41:11 PM:
This was great!!!  In answer to 
MarkusQ's statment it does giv you all 
months, but you will have to scroll 
deep for the results.  to set for use 
with month, get rid of the loop, and 
add the month to the input and to the 
string that builds the input 
date.
Worked Great for me! 
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
10/31/2002 10:10:30 AM:John Overton
Thanks for the votes!  
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
12/16/2002 9:39:24 AM:
Very, very nice.
I have made a 
couple of changes for you to look 
at:
1) 
CREATE PROCEDURE CALENDAR 
(@YEAR INT) AS
set nocount on  -- ADD 
THIS LINE AFTER THE ONE ABOVE
2) 
PRINT "                               
     " + upper(left(cast(@INPUTDATE as 
varchar),3))  --ADD THIS LINE ABOVE THE 
BELOW LINE
    SELECT SUNDAY, MONDAY, 
TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, 
SATURDAY FROM #TEMP
If you make 
these two changes, you will see the 
month centered above each 'calendar' 
and none of the 'rows affected' will 
show. Just the Month and Calendar.
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
12/16/2002 9:42:31 AM:
Please note that the number of spaces 
between the "s in the above suggested 
changes in number 2 is 36.
Have fun, 
Phred
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
Add Your Feedback!
Note:Not only will your feedback be posted, but an email will be sent to the code's author in your name.

NOTICE: The author of this code has been kind enough to share it with you.  If you have a criticism, please state it politely or it will be deleted.

For feedback not related to this particular code, please click here.
 
Name:
Comment:

 

Categories | Articles and Tutorials | Advanced Search | Recommended Reading | Upload | Newest Code | Code of the Month | Code of the Day | All Time Hall of Fame | Coding Contest | Search for a job | Post a Job | Ask a Pro Discussion Forum | Live Chat | Feedback | Customize | SQL Home | Site Home | Other Sites | About the Site | Feedback | Link to the Site | Awards | Advertising | Privacy

Copyright© 1997 by Exhedra Solutions, Inc. All Rights Reserved.  By using this site you agree to its Terms and Conditions.  Planet Source Code (tm) and the phrase "Dream It. Code It" (tm) are trademarks of Exhedra Solutions, Inc.