| | |
How can I create a user defined function
Please support our MS SQL advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
It's pretty easy.
CREATE FUNCTION MyFunction(@variableOne datatype)
RETURNS datatype
AS
BEGIN
-- put function logic here
RETURN @variable
END
Then to call the function, you would use it in any SQL statement. For example
SELECT FIELD1, MyFunction(FIELD2) as ALIAS
FROM SOMETABLE;
Hope this helps
Andy
CREATE FUNCTION MyFunction(@variableOne datatype)
RETURNS datatype
AS
BEGIN
-- put function logic here
RETURN @variable
END
Then to call the function, you would use it in any SQL statement. For example
SELECT FIELD1, MyFunction(FIELD2) as ALIAS
FROM SOMETABLE;
Hope this helps
Andy
Nobody believes the official spokesman, but everybody trusts an unidentified source.
-- Please do not PM me with questions about a thread. If you respond to a thread, then everyone can benefit.
-- Please do not PM me with questions about a thread. If you respond to a thread, then everyone can benefit.
![]() |
Similar Threads
- Can we call a User defined Function using Linked Servers ? (MS SQL)
- User-defined functions (C++)
- User-Defined Function - part 2 (C++)
- Passing a matrix from main function to user defined function. (C++)
- error in user defined string class (C++)
- using(STL)function object (bind2nd) with a user defined function object (C++)
Other Threads in the MS SQL Forum
- Previous Thread: Getting current value in Select Statement
- Next Thread: Do uncompression of disk drives affects my Database?
Views: 10196 | Replies: 2
| Thread Tools | Search this Thread |
Tag cloud for MS SQL
"last age autogrowth business connectingtodatabaseinuse count cursor data database dateadd datediff datepart day" dbsize deadlock delete_trigger exploit getdate hack highperformancecomputing hpc hpcserver2008 ibm iis limit live loop maximum microsoft ms mssql multiple multithreading news number password permission position query reporting result security server services sets single source sql sql-injection sqlserver sqlserver2005 subtype supercomputing supertype tables uniqueid update view weekday





