SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 MS Access to SQL Function
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

rjbautista20
Starting Member

Philippines
2 Posts

Posted - 06/19/2013 :  02:35:45  Show Profile  Reply with Quote
Would like to ask for your help...

I would like to convert my MS Access Function to SQL server function.

hope you can help...

Thanks

Function Paywindows(ByRef Paydate As Date) As Date

If Month(Paydate) = 7 And Day(Paydate) <= 13 Then

Paydate = Month(Paydate) & "/12/" & Year(Paydate)


ElseIf Month(Paydate) = 7 And Day(Paydate) <= 27 Then
Paydate = Month(Paydate) & "/26/" & Year(Paydate)

ElseIf Month(Paydate) = 7 And Day(Paydate) >= 28 Then
Paydate = DateSerial(Year(Paydate), Month(Paydate) + 1, 12)
End if
End function

visakh16
Very Important crosS Applying yaK Herder

India
52249 Posts

Posted - 06/19/2013 :  03:00:27  Show Profile  Reply with Quote

CREATE FUNCTION PayWindows
(
@PayDate datetime
)
RETURNS datetime
AS
BEGIN
DECLARE @PayDate datetime

SET @PayDate = DATEADD(mm,DATEDIFF(mm,0,@PayDate),CASE WHEN MONTH(@PayDate)= 7 AND DAY(@PayDate)<=13  THEN 11 MONTH(@PayDate)= 7 AND DAY(@PayDate)<=27 THEN 25 MONTH(@PayDate)= 7 AND DAY(@PayDate)>=28 THEN 41 END)

RETURN (@PayDate)
END


------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page

rjbautista20
Starting Member

Philippines
2 Posts

Posted - 06/19/2013 :  22:36:23  Show Profile  Reply with Quote
Hi visakh16,

Thanks for your reply. i follow your suggest but, i'm having errors while executing the case statement

Incorrect syntax near the keyword 'return'.

Go to Top of Page

bandi
Flowing Fount of Yak Knowledge

India
2168 Posts

Posted - 06/20/2013 :  00:28:59  Show Profile  Reply with Quote
quote:
Originally posted by rjbautista20

Hi visakh16,
Thanks for your reply. i follow your suggest but, i'm having errors while executing the case statement
Incorrect syntax near the keyword 'return'.


THEN keywords are missing in the CASE Statement...
That should be
CREATE FUNCTION PayWindows
(
@PayDate datetime
)
RETURNS datetime
AS
BEGIN
DECLARE @V_PayDate datetime

SET @V_PayDate = DATEADD(MM,DATEDIFF(MM,0,@PayDate),
			CASE 
			WHEN MONTH(@PayDate)= 7 AND DAY(@PayDate)<=13 THEN 11 
			WHEN MONTH(@PayDate)= 7 AND DAY(@PayDate)<=27 THEN 25 
			WHEN MONTH(@PayDate)= 7 AND DAY(@PayDate)>=28 THEN 41 
			END)
RETURN (@V_PayDate)
END


--
Chandu

Edited by - bandi on 06/20/2013 00:31:36
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
52249 Posts

Posted - 06/20/2013 :  00:41:49  Show Profile  Reply with Quote
Sorry it wasnot THEN...I was missing couple of WHEN clauses

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.06 seconds. Powered By: Snitz Forums 2000