Quantcast
Channel: Transact-SQL forum
Viewing all articles
Browse latest Browse all 23857

Inserting Records From User Defined Function or Using Stored Procedure in Select Statement

$
0
0

I have a function as below which I use to insert Staff Code in Queries


CREATE function [dbo].[Get_StaffCode](@StaffName varchar(255))
returns varchar(10)
as
begin

return (SELECT [STAFF_CODE]
  FROM [dbo].[StaffNames]
  where FullName=@StaffName)
end

Current Usage

insert into Activities(StaffCode,ActivityDate)

Select  [dbo].[Get_StaffCode],ActivityDate from dbo.Activity

What I would like to do is extend this function which will insert a record to StaffNames table or another DataQuality Table if no match is found for the Staff Name.

I cannot insert from a function nor I can create a stored procedure which can be used as the function is used within the select statement.

Any guidance on this is appreciated. I have used this function in many instances and would like not to go and change in every instance..


Viewing all articles
Browse latest Browse all 23857

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>