15,895,084 members
Sign in
Sign in
Email
Password
Forgot your password?
Sign in with
home
articles
Browse Topics
>
Latest Articles
Top Articles
Posting/Update Guidelines
Article Help Forum
Submit an article or tip
Import GitHub Project
Import your Blog
quick answers
Q&A
Ask a Question
View Unanswered Questions
View All Questions
View C# questions
View C++ questions
View Javascript questions
View Visual Basic questions
View Python questions
discussions
forums
CodeProject.AI Server
All Message Boards...
Application Lifecycle
>
Running a Business
Sales / Marketing
Collaboration / Beta Testing
Work Issues
Design and Architecture
Artificial Intelligence
ASP.NET
JavaScript
Internet of Things
C / C++ / MFC
>
ATL / WTL / STL
Managed C++/CLI
C#
Free Tools
Objective-C and Swift
Database
Hardware & Devices
>
System Admin
Hosting and Servers
Java
Linux Programming
Python
.NET (Core and Framework)
Android
iOS
Mobile
WPF
Visual Basic
Web Development
Site Bugs / Suggestions
Spam and Abuse Watch
features
features
Competitions
News
The Insider Newsletter
The Daily Build Newsletter
Newsletter archive
Surveys
CodeProject Stuff
community
lounge
Who's Who
Most Valuable Professionals
The Lounge
The CodeProject Blog
Where I Am: Member Photos
The Insider News
The Weird & The Wonderful
help
?
What is 'CodeProject'?
General FAQ
Ask a Question
Bugs and Suggestions
Article Help Forum
About Us
Search within:
Articles
Quick Answers
Messages
Comments by iamFahhad (Top 13 by date)
iamFahhad
4-Mar-13 3:57am
View
Even after removing the comma, I'm getting the following errors:
Msg 102, Level 15, State 1, Procedure GetWorkingDays2, Line 11
Incorrect syntax near '@startDate'.
Msg 137, Level 15, State 1, Procedure GetWorkingDays2, Line 14
Must declare the scalar variable "@startDate".
Msg 137, Level 15, State 1, Procedure GetWorkingDays2, Line 15
Must declare the scalar variable "@endDate".
Msg 137, Level 15, State 2, Procedure GetWorkingDays2, Line 17
Must declare the scalar variable "@startDate".
Msg 137, Level 15, State 2, Procedure GetWorkingDays2, Line 36
Must declare the scalar variable "@endDate".
Msg 102, Level 15, State 1, Procedure GetWorkingDays2, Line 43
Incorrect syntax near ')'.
iamFahhad
3-Mar-13 23:39pm
View
Thanks.
iamFahhad
2-Mar-13 4:13am
View
I'm getting these errors when I executed your code:
Msg 139, Level 15, State 1, Procedure cat, Line 0
Cannot assign a default value to a local variable.
Msg 137, Level 15, State 2, Procedure cat, Line 164
Must declare the scalar variable "@YourMonth".
This is your code:
alter proc cat
@DateSample DATETIME
as
begin
-- Number of working days between two dates
Declare @LevDays INT, @YourMonth TINYINT=3, @YourYear SMALLINT=2013
DECLARE @fromDate DATETIME, @toDate DATETIME , @ReqMonth SMALLINT, @ReqYear SMALLINT
SELECT @ReqMonth=MONTH(@DateSample),@ReqYear =YEAR(@DateSample)
SELECT @fromDate = CAST(@ReqYear AS VARCHAR(5))+'-'+CAST(@ReqMonth AS VARCHAR(2))+'-'+'01'
SELECT @toDate = DATEADD(DAY,-1,DATEADD(MONTH,1,CAST(@ReqYear AS VARCHAR(5))+'-'+CAST(@ReqMonth AS VARCHAR(2))+'-'+'01' ))
SELECT @fromDate , @toDate
SELECT (DATEDIFF(DAY, @fromDate, @toDate) + 1)
- (DATEDIFF(WEEK, @fromDate, @toDate) * 2)
- (CASE WHEN DATENAME(weekday, @fromDate) = 'Sunday' THEN 1 ELSE 0 END)
- (CASE WHEN DATENAME(weekday, @toDate) = 'Saturday' THEN 1 ELSE 0 END)
-- No of Holidays also we need to deduct.
SELECT E.EmpID, T.LevDays
FROM EmployeeDtls E
INNER JOIN (SELECT EmpID, ISNULL(COUNT(LeaveDate),0)'LevDays'
FROM EmpTab WHERE MONTH(LeaveDate)=@YourMonth AND YEAR(LeaveDate)=@YourYear GROUP BY EmpID) T ON T.EmpID=E.EmpID
END
iamFahhad
2-Mar-13 2:08am
View
Can I use the below code in my function?
create function dbo.GetFirstWorkdayOfMonth(@Year INT, @Month INT)
returns DATETIME
as begin
declare @firstOfMonth VARCHAR(20)
SET @firstOfMonth = CAST(@Year AS VARCHAR(4)) + '-' + CAST(@Month AS VARCHAR) + '-01'
declare @currDate DATETIME
set @currDate = CAST(@firstOfMonth as DATETIME)
declare @weekday INT
set @weekday = DATEPART(weekday, @currdate)
-- 7 = saturday, 1 = sunday
while @weekday = 1 OR @weekday = 7
begin
set @currDate = DATEADD(DAY, 1, @currDate)
set @weekday = DATEPART(weekday, @currdate)
end
return @currdate
end
iamFahhad
2-Mar-13 2:04am
View
Hi Venkatesh,
Please check your eMail. I have already sent you my complete code along with the database table design and the Function - UDF. Please modify it to be able to accept the Month and Year (Ex: June, 2011).
Thanks.
iamFahhad
2-Mar-13 1:22am
View
But Joins can be used only between two tables, right? Here we have only one table, "EmpTab". So how do we use Joins in this scenario? Moreover, since I'm using Stored Procedures, do I have to include the above queries in different Procedures, or in the same procedure? Can you please combine it all within a single Stored Procedure?
iamFahhad
2-Mar-13 0:55am
View
The "EmpID" is of type int, "LeaveDate" is of type DateTime.
iamFahhad
2-Mar-13 0:52am
View
I have table "EmpTab" with two fields "EmpID", "LeaveDate".
So how do I deduct the holidays by the employee for a particular month, say for example, September 2009?
iamFahhad
1-Mar-13 6:41am
View
Your code is working. But how do I modify it to deduct the holidays by the employee in that particular month? Can you add to your code please?
iamFahhad
1-Mar-13 5:12am
View
Yes, exactly. I need to specify the "Month" and "Year" as input.
Here's the procedure:
alter proc cat
as
begin
-- Number of working days between two dates
DECLARE @fromDate DATETIME, @toDate DATETIME , @ReqMonth SMALLINT, @ReqYear SMALLINT
SELECT @ReqMonth=11,@ReqYear =2010
SELECT @fromDate = CAST(@ReqYear AS VARCHAR(5))+'-'+CAST(@ReqMonth AS VARCHAR(2))+'-'+'01'
SELECT @toDate = DATEADD(DAY,-1,DATEADD(MONTH,1,CAST(@ReqYear AS VARCHAR(5))+'-'+CAST(@ReqMonth AS VARCHAR(2))+'-'+'01' ))
SELECT @fromDate , @toDate
SELECT (DATEDIFF(DAY, @fromDate, @toDate) + 1)
- (DATEDIFF(WEEK, @fromDate, @toDate) * 2)
- (CASE WHEN DATENAME(weekday, @fromDate) = 'Sunday' THEN 1 ELSE 0 END)
- (CASE WHEN DATENAME(weekday, @toDate) = 'Saturday' THEN 1 ELSE 0 END)
-- No of Holidays also we need to deduct.
end
iamFahhad
1-Mar-13 1:27am
View
Hi,
Your sql code gets successful. I put it in a procedure "cat". But it does not give any output. When I select it as follows:
select dbo.cat
I'm getting an error as follows:
Msg 4104, Level 16, State 1, Line 124
The multi-part identifier "dbo.cat" could not be bound.
iamFahhad
1-Mar-13 0:23am
View
Hi Prabu,
Where do I insert that piece of code?
What do you think about using MONTH(08) and YEAR(2012)?
I do not want to hard-code the date into the Stored Procedure. I should be able to enter the date as an input.
iamFahhad
28-Feb-13 0:36am
View
No.. It is just a LeaveTable. i.e The table will only keep track of leave taken by the employees. Only if any employee takes a leave, his/her employeeID and date of taking leave will be stored in the table.
Show More