How to created User Functions in T-SQL to include in main select statement, if possible?
Posted on 2011-03-04
I need to use a subselect in a select statement, ie
select ID, (select name from.... where ID1 = @ID1 and ID2 = @ID2) as Name from .....
Now this subselect has got more complicated so rather recopy this sql all over the place I was wondering whether it was possible to just create a User Function/Stored Function/Stored Procedure instead and if possible how to do it. So instead I would hope to:
select ID, (GetName(@ID1,@ID2) as Name from ...
So my question is really about is GetName possible and how to do it?