Theme Graphic
Theme Graphic

Jonesy's Great Code Archive

This is for me, not you. But I hope you find it useful none-the-less. Suggestions or general comments are appreciated.
Posted on Tuesday, August 25, 2009 at 10:24 AM

How to create and use a function in MSSQL

First we need to create the function...

CREATE FUNCTION dbo.AddTwoNumbers(@Value1 as int, @Value2 as int)
	RETURNS int
BEGIN
	DECLARE @Result int
	SET @Result = @Value1 + @Value2
	RETURN @Result
END
GO


Here is how we actually use the function...

SELECT dbo.AddTwoNumbers(5, 8) AS Result
GO


The SELECT statement outputs the integer 13.
Comments: 0 Tags: MSSQL, Create Function

 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.