If I have a value stored in SQL Server as an integer, say NumOfUnits sold, and I want to return that value based on an ID field to use in the UI of my ASP.NET app, what is the best way to do this? Currently, I am writing an Scalar valued UDF like this in SQL Server:
but in my data access layer and in UI, I seem to keep having issues with variable typing. I find that sometimes I have to use CINT/CTYPE or some such function or else the value will not render correctly.
Is a scalar UDF the way to go on this, or is there a better way?
Code:
CREATE FUNCTION [dbo].[udf_GetNumOfUnitsSoldByID]
(
@TicketID int
)
RETURNS int
AS
BEGIN
RETURN
(
SELECT NumUnitsSold
FROM Inventory
WHERE ticketid = @TicketID
)
END
but in my data access layer and in UI, I seem to keep having issues with variable typing. I find that sometimes I have to use CINT/CTYPE or some such function or else the value will not render correctly.
Is a scalar UDF the way to go on this, or is there a better way?