Afternoon,I am trying to do what I used to do with oracle, never thought I'd say that, create a reusable piece of code to return data from a select statement. All I want is if I put in a unit: job, material or sales order I want the program returned. I tried a couple of ways with no success. What I'm trying to do is embed the function/sp into a select statement:Like so:select function_name(job) as Program, jobfrom job
I have a function:ALTER FUNCTION [dbo].[GetProgramName]( -- Add the parameters for the function here @Unit nvarchar(25))RETURNS varchar(30)ASBEGIN -- Declare the return variable here DECLARE @Program varchar(30) -- Add the T-SQL statements to compute the return value here select @Program = program FROM vw_GetProgram WHERE unit = @Unit -- Return the result of the function RETURN @ProgramEND
and a stored proc CREATE PROCEDURE sp_GetProgramName @Unit nvarchar(25)ASBEGIN SET NOCOUNT ON; select program FROM vw_GetProgram WHERE unit = @UnitENDGO
Any ideas would be great. ThanksLaura