September 26, 2016 at 2:00 pm
How to call function in a select statement of the stored procedure.
I have a function where it takes Des1 and Des2 as parameters.From the query of the function i will get 2 results based on these parameters.
one is code another one is codedesc ( these are the columns selecting from function) and I want to use these columns in above stored procedure.
now i have to call these two columns in the above stored procedure in select statement.How to call this?
September 26, 2016 at 2:03 pm
Err, what do you mean by 'select statement of the stored procedure'?
I assume this is a table-valued UDF. If so, then it's used in the FROM clause of a select
SELECT FunctionColumn1, FunctionColumn2, ... FROM dbo.UserDefinedFunctionName(Parameter1, Parameter2, ...)
Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability
September 26, 2016 at 2:27 pm
Yes,This is UDF. I want to use this function in my stored procedure.
FUNCTION dbo.Blabla
(
@DE1 Varchar(100),
@DE2 Varchar(100)
)
RETURNS TABLE
AS
RETURN
(
SELECT
substring(CAST(COL1 AS VARCHAR(20)),1,CAST(CHARINDEX('-',COL1) AS VARCHAR(20)) -1) AS ,
substring(COL1,CHARINDEX('-',COL1)+1,(Len(COL1))) AS [lCode]
FROM [Emp] A
Where DE1=@DE1 and DE2=@DE2
AND DT = (Select MAX(DT) From dbo.Emp B Where A.DE1=B.DE1 and A.DE2=B.DE2)
)
Now i want to use this function in my stored procedure to get code and lcode values?
How to approach this based on parameters?
September 26, 2016 at 2:35 pm
Since your UDF returns a table, you could probably use CROSS APPLY to pass values from the other table (the source for the two parameters) and then return the whole thing in one result set. Kind of hard to tell with the sketchy description of the problem.
September 27, 2016 at 1:31 am
mcfarlandparkway (9/26/2016)
Now i want to use this function in my stored procedure to get code and lcode values?
With the really vague question and lack of details, hard to say anything useful. Can you explain further?
Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability
September 27, 2016 at 7:37 am
Viewing 6 posts - 1 through 5 (of 5 total)
You must be logged in to reply to this topic. Login to reply