I’m looking to create what I would think is simple.
I want a user defined function which takes a row from a table as imput and returns a scalar value.
Something like
select
mt.Id,
MyUDF(mt)
from M
MyTable mt
where mt.Price > 0
I understand that I can pass in the Id to the UDF, and then lookup the values from within the UDF, but that seems like a lot of extra work.
As marc_s said, the idea of sending a “row” as an object in T-SQL isn’t present. You can send the data from the row as individual values, but not the row itself.
A computed column on the table itself would probably make more sense. If the value is directly dependent on the values present in the row (and not dependent on any external values), then this would be a solution.
For example, say I have this table:
If I wanted a computed column for
FullName, my table declaration would look like:I could also add it after the fact with an
ALTERstatement