Link to home
Start Free TrialLog in
Avatar of Allan
AllanFlag for United States of America

asked on

Check and Create UDF

HI Experts,

This should be easy. How to check if udf exist, if not then create a blank udf.

IF NOT EXISTS (select name
from sysobjects
where type in ('FN', 'IF', 'TF')
  and name = 'Some_udf')
      EXEC('CREATE FUNCTION dbo.Some_udf AS RETURN 0')
GO

-- The Alter Statement goes here

ALTER FUNCTION [dbo].Some_udf
(
  @blah01 CHAR(13),
  @blah02 CHAR(2)
)  
RETURNS CHAR(2)
AS
BEGIN
END
RETURN ....
ASKER CERTIFIED SOLUTION
Avatar of Aneesh
Aneesh
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Allan

ASKER

Thanks all for your replies.
correct me if i'm wrong; one reason why i don't want to drop is because the object will lose it's permission if dropped.
Correct, so you can check for non-existence and create as you were but then you would have to explicitly GRANT permissions in that case; therefore, you can always drop and then after creation add GRANT statements you need.
Avatar of Allan

ASKER

THanks. Seems that's more work than using Alter -- permission is set once and you don't have to deal with it.
Avatar of Allan

ASKER

Thanks for all your help!
Avatar of Allan

ASKER

splitting points ..