SQL Sagot
SQL Sagot
Create a database named LabDB and create a table named Records and put the
following data.
Code:
CREATE TABLE Records
(Id int IDENTITY(1,1) PRIMARY KEY,
LastName varchar(255),
FirstName varchar(255),
Age int,
Gender varchar(255),
Level varchar(255)
)
2 – 4. Fetch each data from table Records using a while loop and evaluate them
using IF-ELSE and CASE Statements. If the returning age is 14 to 16, change the
level to Freshman. If 17 to 19, change it to Sophomore. If 20 to 22, change it to
Junior. Lastly, if 23 to 25, change it to Senior. If the returning age is not in
the given range, change their level to ‘Unknown’.
Querying data through IF-ELSE statement should display their level to LOWERCASE.
Else, using the CASE statement should display their level to UPPERCASE.
Display the updated level of each data using a PRINT statement.
Code: (IF-ELSE and LOWERCASE)
BEGIN
This study source was downloaded by 100000846644680 from CourseHero.com on 09-17-2022 18:34:16 GMT -05:00
https://www.coursehero.com/file/151052071/SQL-SAGOTtxt/
DECLARE @Level AS VARCHAR(50);
END
END
ELSE
BEGIN
UPDATE Records SET Level = 'Unknown' WHERE Id = @OrderCounter;
END
PRINT 'Id: ' + CONVERT(varchar(10),@Id) + ' | Name: ' + @Name + ' | Age: ' +
CONVERT(varchar(10),@Age) + ' | Gender: ' + @Gender + ' | Level: ' + @Level;
SET @OrderCounter += 1;
END
END
This study source was downloaded by 100000846644680 from CourseHero.com on 09-17-2022 18:34:16 GMT -05:00
https://www.coursehero.com/file/151052071/SQL-SAGOTtxt/
DECLARE @Name AS VARCHAR(50);
DECLARE @Age INT;
DECLARE @Gender AS VARCHAR(50);
DECLARE @Level AS VARCHAR(50);
PRINT 'Id: ' + CONVERT(varchar(10),@Id) + ' | Name: ' + @Name + ' | Age: ' +
CONVERT(varchar(10),@Age) + ' | Gender: ' + @Gender + ' | Level: ' + @Level;
SET @OrderCounter += 1;
END
END
This study source was downloaded by 100000846644680 from CourseHero.com on 09-17-2022 18:34:16 GMT -05:00
https://www.coursehero.com/file/151052071/SQL-SAGOTtxt/
Powered by TCPDF (www.tcpdf.org)