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

Execute store procedure based on table results

$
0
0

I need to exec a stored procedure for each row in a table where one column is null. The stored procedure inserts data into a second table and then sets the null column to the PK value of the second table. I don't know how to build the loop so it only executes the stored procedure on the NULL rows all in one click...

DECLARE
@getAcctOpenDate datetime,
@getAcctCloseDate datetime,
@getAccountID int,
@getUserID int,
@getAcctName varchar(50),
@getAcctKey int

SELECT
@getAcctName = NA_ACCT_INFO_OUT,
@getAcctOpenDate = DA_ACCT_OPEN,
@getAcctCloseDate = DA_ACCT_CLOSE,
@getUserID = (SELECT UserID FROM dbo.User_Info WHERE UserType = 'CONV'),
@getAcctKey = account_key
FROM dbo.NewAccounts
WHERE account_key IS NULL

exec dbo.insNewAccounts
@account_type_key = 2,
@account_subtype_key = NULL,
@status_key = 3,
@source_key = 3,
@acctOpenDt = @getAcctOpenDate,
@acctCloseDt = @getAccountCloseDate,
@account_key = @getAccountID output,
@created_dttm = getdate()
@created_by = @getUserID
@updated_dttm = getdate()
@updated_by = @getUserID
UPDATE dbo.NewAccounts
SET account_key = @getAccountID
WHERE NA_ACCT_INFO_OUT = @getAcctName




Viewing all articles
Browse latest Browse all 23857

Trending Articles



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