Function - SCALAR

A scalar function returns exactly one value, unlike a 'table function' which returns a ... table. 

This is our template for the scalar function. We (www.4Penny.net) are professional consultants and work at customers across the country. It's convenient to have these templates on the internet to be able to easily access them and get to coding.

"Doesn't SSMS have templates?" you ask. Of course it does. But ours are better, cleaner, quicker. Easier to access. 

 

-- Scalar Function template, provided by www.DynDeveloper.com
-- Please leave the line above in your code
 
IF EXISTS (SELECT *
       FROM   sysobjects
       WHERE  name = N'ddf_ChangeMe')
    DROP FUNCTION ddf_ChangeMe
GO
 
 
CREATE FUNCTION ddf_ChangeMe (@InputVariable AS int)
--to test this, run this script:
-- SELECT dbo.ddf_ChangeMe(5) as MyFunction
 
Returns int
 
AS
begin
    declare @out INT = 0
 
    SET @out = @InputVariable * 2
 
    return (@out)
end
go
grant exec on ddf_ChangeMe to public

 

 


RealWorldCode gives developers practical, real‑world solutions with clean, working code — no fluff, no theory, just answers.
Links
Home
Knowledge Areas
Sitemap
Contact
Et cetera
Privacy Policy
Terms and Conditions
Cookie Preferences