473,387 Members | 1,536 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Why is the "EndDate" not getting executed in my SQL Function (UDF)?

4
I need to pass the @startDate and @endDate as variables to @range in the code given below. But when I execute the below code, I'm getting the Error as follows. What is going wrong in my code, and how can I correct it?

Errors:

Msg 102, Level 15, State 1, Procedure GetWorkingDays2, Line 4
Incorrect syntax near ')'.
Msg 178, Level 15, State 1, Procedure GetWorkingDays2, Line 19
A RETURN statement with a return value cannot be used in this context.


Expand|Select|Wrap|Line Numbers
  1. use employee
  2. go
  3.  
  4. CREATE FUNCTION dbo.GetWorkingDays2 
  5. @InputDate SMALLDATETIME, 
  6. ); 
  7. RETURNS INT 
  8. AS 
  9. BEGIN 
  10. DECLARE @range INT, 
  11. @startDate SMALLDATETIME,
  12. @endDate SMALLDATETIME;
  13.  
  14. SET @startDate = DATEADD(dd, -(DAY(@InputDate)-1), @InputDate);
  15. SET @endDate = DATEADD(dd, -(DAY(DATEADD(mm, 1, @InputDate))), DATEADD(mm, 1, @InputDate));
  16. SET @range = DATEDIFF(DAY, @startDate, @endDate)+1; 
  17.  
  18. RETURN 
  19. SELECT 
  20. @range / 7 * 5 + @range % 7 - 
  21. SELECT COUNT(*) 
  22. FROM 
  23. SELECT 1 AS d 
  24. UNION ALL SELECT 2 
  25. UNION ALL SELECT 3 
  26. UNION ALL SELECT 4 
  27. UNION ALL SELECT 5 
  28. UNION ALL SELECT 6 
  29. UNION ALL SELECT 7 
  30. ) weekdays 
  31. WHERE d <= @range % 7 
  32. AND DATENAME(WEEKDAY, @endDate - d + 1) 
  33. IN 
  34. 'Saturday', 
  35. 'Sunday' 
  36. ) - (select count(*) from dbo.EmpTab Where EmpID = 123)
  37. ); 
  38. END 
  39. GO



Expand|Select|Wrap|Line Numbers
  1. --PRINT dbo.getWorkingDays2('20130228')
Mar 4 '13 #1
1 1408
Rabbit
12,516 Expert Mod 8TB
Delete the semicolon on line 7. A semicolon ends a statement.
Mar 4 '13 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: screenwriter776 | last post by:
Hi, folks - Perhaps you could help me with a search form I am building. I have a table with a field in it. I want to return dates inside two parameters the user enters into a search form:...
0
by: John Haigh | last post by:
Should possibly have an "add" method in a PostingObject class in the constructor of PostingObject. will call to add a Posting to the ? Does this make sense? My sense is that a PostingObject needs a...
3
by: | last post by:
Hello, I am hoping someone else has thought about a date time calculation i need to perform. I would like to be able to calculate the number of "working minutes" between 2 dates, given my...
3
by: Barbara Lindsey | last post by:
I have a case where I am collecting a "Start Date" and an "End Date". I would like to default the "End Date" to the "Start Date" value if only the "Start Date" is entered. I tried setting this as...
1
by: Kosmös Pollard | last post by:
Hey guys, I'm rather new to access and can not seem to figure out what is wrong with this code I will post below...but first...it was working perfectly fine before I added this: recSet2.Edit...
19
by: c9stealth | last post by:
I'm still working on a DataBase for my unit and I need to find a way to enter in two dates and have those dates hold the value of the time between them. say i enter in 01/01/2007 and 02/01/2007. ...
3
by: Peter K | last post by:
Hi I am having trouble writing a webservice which is to provide access to the functions of an existing codebase. The existing code may not be changed at all. For example, I obtain an...
2
by: rmmahara | last post by:
Hi Folks, I've been reading these forums for a while and now I'm in desperate need of help, so I thought I'd post! Background: I'm creating a Service Dashboard to track my team's adherence...
0
by: tgkprog | last post by:
hi i'm trying to use Win32::IEAutomation to automate clickbank.com navigation and page saving i can login and go to the https://www.clickbank.com/account/showTransactions.htm page but cannot...
2
by: thj | last post by:
Hi. I've got this form that I'm trying to validate: <form id="periodForm" action="" method="post"> <p> Periode: <input id="startDate" name="startDate" type="text" size="7" value="<%=...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.