Nate Pet
Nate Pet

Reputation: 46222

sql calling custom function - tsql

I am doing the following:

    Insert into table1 
   (Phone#) values @Phone

There is a custom function which will format the phone number. It accepts as input parameter the phone number and returns the formatted version.

I tried the following but not sure it would not work:

    Insert into table1 
   (Phone#) values fn_phone(@Phone)

It says fn_phone is not a recognized built in function name. Am I doing something wrong on how I am calling fn_phone?

Upvotes: 3

Views: 1281

Answers (3)

Moe Sisko
Moe Sisko

Reputation: 12015

Assuming the function is from "dbo" schema :

    Insert into table1 
   (Phone#) values (dbo.fn_phone(@Phone))

Upvotes: 0

Andrey Gurinov
Andrey Gurinov

Reputation: 2885

Use two-part name when you are calling UDF

Try this:

Insert into table1  
   (Phone#) select dbo.fn_phone(@Phone) 

Upvotes: 7

Taryn
Taryn

Reputation: 247710

try:

Insert into table1 (Phone#) 
SELECT dbo.fn_phone(@Phone) (or whatever schema your function is in)

Upvotes: 1

Related Questions