Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
.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