x
login about faq Site discussion (meta-askssc)

How to Execute Sql UDF function

I want to convert nvarchar to ascii value, So I want to create udf function, but i don't know to execute the function.

please anyone know, give me the solutions

more ▼

asked Oct 25 '09 at 10:52 AM in Default

Prabhakar gravatar image

Prabhakar
22 2 2 2

(comments are locked)
10|1200 characters needed characters left

2 answers: sort oldest

A scalar function is basically an expression. You use it in a query just as you would a column name, variable, or formula. Obviously you have to pass parameters to it in the query.

select colA, colB, @amt, colA+colB, dbo.ufNvarcharToAscii(colC)

Although this is outside the scope of your question, a scalar function should not be confused with a table-valued function. A scalar function produces a single result value, while a table-valued function can produce a set of rows and is used either like a table, or in conjunction with APPLY. Inline table-valued functions are treated much like views by the optimizer and can produce performance benefits over scalar functions when applied to a large number of rows.

select * from dbo.tfnListOpenOrdersForCustomerNo(custno)

select c.custNo,c.custname,t.orderno
from dbo.Customers c
cross apply dbo.tfnListOpenOrdersForCustomerNo(custno) as t
more ▼

answered Oct 25 '09 at 11:09 AM

Bob Hovious gravatar image

Bob Hovious
1.6k 5 6 9

(comments are locked)
10|1200 characters needed characters left

Say you have created that UDF - then you would call it with

SELECT schema.functionname(parameter)

So you might say

SELECT @asciiValue = dbo.ConvertToAscii(@nvarcharValue)

However, in this case, you would be well advised to use the ASC built in function.

more ▼

answered Oct 25 '09 at 11:08 AM

Matt Whitfield gravatar image

Matt Whitfield ♦♦
29.2k 56 63 87

Thanks for sorting out my formatting Mel! :)

Oct 26 '09 at 06:33 AM Matt Whitfield ♦♦
(comments are locked)
10|1200 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments



Facebook logo Follow Ask SSC on Facebook
Find Ask SSC on Google+
linkedin logo Find us on LinkedIn

Topics:

x49

asked: Oct 25 '09 at 10:52 AM

Seen: 9257 times

Last Updated: Oct 25 '09 at 10:52 AM

Copyright © 2002-2012 Simple Talk Publishing. All Rights Reserved. If you have any queries, please contact the site administrators.
Ask SQL Server Central is a community service provided by Red Gate.