USEING SQL Server Database Development Open the AP database using the SQL Server
ID: 3810776 • Letter: U
Question
USEING SQL Server Database Development
Open the AP database using the SQL Server 2012 Management Studio. Please make sure you review the SQL syntax for each query that is created.
Please create solutions to the following queries:
1. Write a select statement that returns four columns based on the InvoiceTotal column of the invoices table, AP database.
a. Use the CAST function to return the first column with 0 digits to the right of the decimal point
b. Use the CAST function to return the second column with a $ in front of the value.
c. Using the CONVERT function to return the third column with the smallest precision in mind to return the scale of 3.
d. Use the CONVERT function to return the fourth column with a $ in front and back of the value. There should be no spaces between the symbols and number. i.e $3,813.33$
One row example without the headers:
3813 $3813.33 3813.330 $3,813.33$
2. Write a SELECT statement that returns two columns based on the Vendors table. The first column, Contact, is the vendor contact name, the second is the phone.
a. For the contact, the first name is followed by last name initial (for example, “John S.”)
b. The second column, Phone, is the VendorPhone column without the area code.
Criteria:
1) Only return rows for those vendors in the 559 area code. You can only use the numbers “559” in the search, no parenthesis.
2) Sort the result set by last name.
One row example with headers:
Contact Phone
Thom A. 555-8484
Explanation / Answer
Hi,
As the table structure is not given, I assume column names as colA, colB....etc.
Answer 1
Ans a- select cast(round(Column1,0) as decimal(10,0)) from table_name;
Ans b- select '$' + Column2 from table_name;
Ans c- select round(Column3,3) from table_name;
Ans d- select '$' + Column4 + '$' from table_name;
Answer 2
Ans 2 select first_name + ' ' + substring(last_name,1,1) +'.' , substring(VendorPhone ,5,len(VendorPhone )) as Contact from table_name where substring(VendorPhone ,1,3)='559';
first_name--> column which holds first name
last_name--> column which holds last name
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.