TSQL Function passing a date

Hi Experts,

I have this function:
ALTER FUNCTION [dbo].[fncUtlDateEnding]
(@IncomingDate as datetime, @DatePart as nvarchar(10))
RETURNS datetime
AS
BEGIN
	DECLARE @OutgoingDate as datetime
	
	If @DatePart = 'yyyy' 
		SET @OutgoingDate =DATEADD(yyyy, 1 + DATEDIFF(yyyy, 0, @IncomingDate), 0) - 1

	If  @DatePart = 'mm' 
		SET @OutgoingDate = DATEADD(mm, 1 + DATEDIFF(mm, 0, @IncomingDate), 0) - 1



	RETURN @OutgoingDate
END

Open in new window


And I have a table that has the column that I would like to change the date to be the last day of the month.

TableName.Date6

I would like to know how to fun the function to get what I am looking for?

Please help and thanks.
Amour22015Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Vitor MontalvãoMSSQL Senior EngineerCommented:
UPDATE TableName
SET Date6 = fncUtlDateEnding(Date6,'mm')

Open in new window

NOTE: Test this command in a testing/development environment before running it in Production.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Deepak ChauhanSQL Server DBACommented:
You can also check the value by selecting before update. If it is giving the desired result what you are looking for the update the table.

Select Date6, dbo.fncUtlDateEnding(Date6,'mm') from TableName

If you are good with result then update.

UPDATE TableName
SET Date6 = dbo.fncUtlDateEnding(Date6,'mm')
Amour22015Author Commented:
Great thanks for helping.  DeepakChauhan  from what I can see of your name? are you from Punjabi India?
Deepak ChauhanSQL Server DBACommented:
Good catch, Yes i am from India Delhi.
Amour22015Author Commented:
ਅਧਿਕਤਮ - Sat Shri Akal ji. - Yes the Deepak is what really gave location away,
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Query Syntax

From novice to tech pro — start learning today.