Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
GirishKumarSharma
Starting Member
10 Posts |
Posted - 2011-11-09 : 00:12:24
|
| Hi,After searching a lot in google i think i have to create my login in sql forum to get SQL Server 2005 help.I need a procedure which will accept a number i.e. month and will return me the number of days something like this :Days CountSunday Number of Sundays in given monthMonday Number of Mondays in given monthTuesday .... Wednesday ....ThursdayFridaySaturdayI am using SQL Server 2005 and visual basic 6 for a project. In this project, user will select Sunday,Monday... from combo box and in another combo box which will be populated by above procedure by number of sunday,mondays respectively. I wish to pass the current month to the procedure and then respective calculations.Please guide me, how do i get. I am sure, the code is available in the forum somewhere, but not finding (new bie).Thanks and RegardsGirish Sharma |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2011-11-09 : 00:59:17
|
something likeCREATE PROC DayinMonthCount@MonthDate datetime,@day varchar(10)ASDECLARE @MonthStart datetime,@EndDate datetimeSELECT @MonthStart=DATEADD(mm,DATEDIFF(mm,0,@MonthDate),0),@EndDate=DATEADD(mm,DATEDIFF(mm,0,@MonthDate)+1,0)-1SELECT [Day],COUNT(*) AS daycntFROM dbo.CalendarTable(@MonthStart,@EndDate,0,0)GROUP BY [Day] calendar table can be found in below linkhttp://visakhm.blogspot.com/2010/02/generating-calendar-table.html------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
GirishKumarSharma
Starting Member
10 Posts |
Posted - 2011-11-09 : 01:38:25
|
| Thank you very much for such a great help. Kindly let me know how do i execute and pass the variable.I have created the procedure though.When i tried to run using Management Studio's Query Analyzer windows :USE [ScheduleTask]GODECLARE @return_value intEXEC @return_value = [dbo].[DayinMonthCount] @MonthDate = N'09/11/2011', @day = N'Sunday'SELECT 'Return Value' = @return_valueGOI got :Friday 5Monday 4Saturday 4Sunday 4Thursday 5Tuesday 4Wednesday 4I wish to order by too as starting from Sunday and ending at Saturday.RegardsGirish Sharma |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2011-11-09 : 01:46:11
|
quote: Originally posted by GirishKumarSharma Thank you very much for such a great help. Kindly let me know how do i execute and pass the variable.I have created the procedure though.When i tried to run using Management Studio's Query Analyzer windows :USE [ScheduleTask]GODECLARE @return_value intEXEC @return_value = [dbo].[DayinMonthCount] @MonthDate = N'09/11/2011', @day = N'Sunday'SELECT 'Return Value' = @return_valueGOI got :Friday 5Monday 4Saturday 4Sunday 4Thursday 5Tuesday 4Wednesday 4I wish to order by too as starting from Sunday and ending at Saturday.RegardsGirish Sharma
sorry didnt get thathow you want to pass variable?do you mean return values through output variable?------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2011-11-09 : 01:48:01
|
quote: Originally posted by visakh16 something likeCREATE PROC DayinMonthCount@MonthDate datetime,@day varchar(10)ASDECLARE @MonthStart datetime,@EndDate datetimeSELECT @MonthStart=DATEADD(mm,DATEDIFF(mm,0,@MonthDate),0),@EndDate=DATEADD(mm,DATEDIFF(mm,0,@MonthDate)+1,0)-1SELECT [Day],COUNT(*) AS daycntFROM dbo.CalendarTable(@MonthStart,@EndDate,0,0)GROUP BY [Day] calendar table can be found in below linkhttp://visakhm.blogspot.com/2010/02/generating-calendar-table.html------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/
what is the purpose of @day ? It is not used KH[spoiler]Time is always against us[/spoiler] |
 |
|
|
GirishKumarSharma
Starting Member
10 Posts |
Posted - 2011-11-09 : 01:57:54
|
>how you want to pass variable?I wish to pass the current date to the procedure and then in visual basic 6 i have one combo box with day names like :Sunday, Monday.... Saturday.User selected any day... After that selection of day there will be 4/5 check boxes will be visible and in these check boxes user will check/uncheck the value of these check boxes.These check boxex values will be stored in a table something like :NameofDay Ch1, Ch2, Ch3, Ch4, Ch5Wednesday Yes Yes Means, user has selected Wednesday and he checked the first and 3rd check box. Here 5 check boxes are visible because there are 5 wednesdays in the current month / given date from dtpicker control.If user selected a day which is having 4 counts then 4 check boxes will be visible accordingly.Please let me know, i am clear in my reply or not?RegardsGirish Sharma |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2011-11-09 : 02:44:03
|
quote: Originally posted by GirishKumarSharma >how you want to pass variable?I wish to pass the current date to the procedure and then in visual basic 6 i have one combo box with day names like :Sunday, Monday.... Saturday.User selected any day... After that selection of day there will be 4/5 check boxes will be visible and in these check boxes user will check/uncheck the value of these check boxes.These check boxex values will be stored in a table something like :NameofDay Ch1, Ch2, Ch3, Ch4, Ch5Wednesday Yes Yes Means, user has selected Wednesday and he checked the first and 3rd check box. Here 5 check boxes are visible because there are 5 wednesdays in the current month / given date from dtpicker control.If user selected a day which is having 4 counts then 4 check boxes will be visible accordingly.Please let me know, i am clear in my reply or not?RegardsGirish Sharma
the checkbox logic have to be done at front endat sql this should be procCREATE PROC DayinMonthCount@MonthDate datetime,@day varchar(10)ASDECLARE @MonthStart datetime,@EndDate datetimeSELECT @MonthStart=DATEADD(mm,DATEDIFF(mm,0,@MonthDate),0),@EndDate=DATEADD(mm,DATEDIFF(mm,0,@MonthDate)+1,0)-1SELECT [Day],COUNT(*) AS daycntFROM dbo.CalendarTable(@MonthStart,@EndDate,0,0)WHERE [Day]=@dayGROUP BY [Day] and cell it like EXEC DayinMonthCount '2011-10-01','Tuesday'------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
GirishKumarSharma
Starting Member
10 Posts |
Posted - 2011-11-09 : 03:26:09
|
| Thank you so much.RegardsGirish Sharma |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2011-11-09 : 03:30:18
|
| wc------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
|
|
|
|
|