Question

Can someone please help me with a DECLARE, SET, PRINT in sql server. my issue is variable 3 does not add up to 99999.99? I am so frustrated CHAPTER 14 - USING VARIABLES IN SCRIPTS --- Use the AP datab...

Can someone please help me with a DECLARE, SET, PRINT in sql server. my issue is variable 3 does not add up to 99999.99? I am so frustrated

CHAPTER 14 - USING VARIABLES IN SCRIPTS ---

Use the AP database.
Create 3 variables named anything you want.
Set the first variable equal to 9876.22.
Set the second variable equal to 187.69.
Set the third variable equal to the sum of the first and second variables.
Use a PRINT statement to print "The value of variable 3 is: 99999.99, where 99999.99 is the value of the variable 3.

DECLARE @Variable1 as decimal(10,2), @Variable2 decimal(10,2)
DECLARE @Variable3 varchar(20)

SET @Variable1 = 9876.22
SET @Variable2 = 187.69
SET @Variable3 = SUM(@Variable1 + @Variable2)

PRINT CONVERT(DECIMAL(10,2), @VARIABLE1)
PRINT CONVERT(DECIMAL(10,2), @VARIABLE2)
PRINT CONVERT(DECIMAL(10,2), @VARIABLE3)

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Need to change the variable1 and variable2 value to get the output 99999.99 of variable3

CREATE PROCEDURE ADDNUMBER
AS
DECLARE @Variable1 as decimal(10,2), @Variable2 decimal(10,2) --declare variable1,variable2
DECLARE @Variable3 varchar(20) --declare variable3

SET @Variable1 = 9876.22 --assign the value to variable1
SET @Variable2 = 90123.77 --assign the value to variable2

--SET @Variable1 = 9876.22 --assign the value to variable1
--SET @Variable2 = 187.69   --assign the value to variable2

SET @Variable3 = SUM(@Variable1 + @Variable2) --add the variable1 and variable2 and assign the value to variable3

PRINT CONVERT(DECIMAL(10,2), @VARIABLE1) --print variable1
PRINT CONVERT(DECIMAL(10,2), @VARIABLE2) --print variable2
PRINT CONVERT(DECIMAL(10,2), @VARIABLE3) --print variable3

output:

create a procedure select the code and press execute button to create a procedure

CREATE PROCEDURE [dbo]. [ADDNUMBER] DECLARE @Variable1 as decimal (1e,2), @Variable2 decimal (10,2) --declare variable1,varia

Now write EXECUTE ADDNUMBER to execute the procedure

CREATE PROCEDURE [dbo].[ADDNUMBER AS DECLARE @Variablei as decimal(10,2), @Variable2 decimal(10,2) -declare variable1,variabl

Add a comment
Know the answer?
Add Answer to:
Can someone please help me with a DECLARE, SET, PRINT in sql server. my issue is variable 3 does not add up to 99999.99? I am so frustrated CHAPTER 14 - USING VARIABLES IN SCRIPTS --- Use the AP datab...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT