Question: - - Create the stored procedure CREATE PROCEDURE cs 4 3 1 _ question 4 AS BEGIN - - Declare variables DECLARE @outputString NVARCHAR (
Create the stored procedure
CREATE PROCEDURE csquestion
AS
BEGIN
Declare variables
DECLARE @outputString NVARCHARMAX
DECLARE @vendorid INT
DECLARE @vendorname NVARCHAR
DECLARE @invoicenumber NVARCHAR
DECLARE @balancedue DECIMAL
Initialize the output string
SET @outputString
Declare and set up the cursor
DECLARE invoicecursor CURSOR FOR
SELECT vvendorid vvendorname, iinvoicenumber, iinvoicetotal ipaymenttotal AS balancedue
FROM invoices i
JOIN vendors v ON ivendorid vvendorid
WHERE iinvoicetotal ipaymenttotal Filter invoices with a balance due $
Open the cursor
OPEN invoicecursor
Fetch data into variables and build the output string
FETCH NEXT FROM invoicecursor INTO @vendorid @vendorname, @invoicenumber, @balancedue
WHILE @@FETCHSTATUS
BEGIN
SET @outputString @outputString CAST@vendorid AS NVARCHAR
@vendorname
@invoicenumber
CONVERTNVARCHAR @balancedue
FETCH NEXT FROM invoicecursor INTO @vendorid @vendorname, @invoicenumber, @balancedue
END
Close and deallocate the cursor
CLOSE invoicecursor
DEALLOCATE invoicecursor
Display the output string
SELECT @outputString AS Result
END
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
