Skip to content

Instantly share code, notes, and snippets.

@manoj-choudhari-git
Last active July 21, 2021 20:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save manoj-choudhari-git/6d36552c9c62cffe3e19cb9f1f9c9760 to your computer and use it in GitHub Desktop.
Save manoj-choudhari-git/6d36552c9c62cffe3e19cb9f1f9c9760 to your computer and use it in GitHub Desktop.
.NET EF Core - A scalar valued function for a demo
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE FUNCTION [dbo].[GetStudentsCountWithSameLastName]
(
@lastName nvarchar(50)
)
RETURNS INT
AS
BEGIN
-- Variable
DECLARE @numberOfStudents int;
-- Populate number of records variable
SELECT @numberOfStudents = COUNT(*)
FROM Students
WHERE LastName = @lastName;
-- Return the number of records
RETURN @numberOfStudents;
END
GO
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment