AdventureWorks Database: Get a newdate by adding two days with current date

SQL Query - AdventureWorks: Exercise-114 with Solution

114 From the following table write a query in SQL to obtain a newdate by adding two days with current date for each salespersons. Filter the result set for those salespersons whose sales value is more than zero.

Sample table: Sales.SalesPerson

Click to view Full table

Sample table: Person.Person

Click to view Full table

Sample table: Person.Address

Click to view Full table

Sample Solution:

SELECT p.FirstName, p.LastName  
 	,(now() + INTERVAL '2 day') AS "New Date" 
FROM Sales.SalesPerson AS s   
    INNER JOIN Person.Person AS p   
        ON s.BusinessEntityID = p.BusinessEntityID  
    INNER JOIN Person.Address AS a   
        ON a.AddressID = p.BusinessEntityID  
    AND SalesYTD <> 0;

Sample Output:

firstname|lastname         |New Date                     |
Michael  |Blythe           |2022-11-02 14:28:09.304 +0530|
Linda    |Mitchell         |2022-11-02 14:28:09.304 +0530|
Jillian  |Carson           |2022-11-02 14:28:09.304 +0530|
Garrett  |Vargas           |2022-11-02 14:28:09.304 +0530|
Tsvi     |Reiter           |2022-11-02 14:28:09.304 +0530|
Pamela   |Ansman-Wolfe     |2022-11-02 14:28:09.304 +0530|
Shu      |Ito              |2022-11-02 14:28:09.304 +0530|
José     |Saraiva          |2022-11-02 14:28:09.304 +0530|
David    |Campbell         |2022-11-02 14:28:09.304 +0530|
Tete     |Mensa-Annan      |2022-11-02 14:28:09.304 +0530|
Lynn     |Tsoflias         |2022-11-02 14:28:09.304 +0530|
Rachel   |Valdez           |2022-11-02 14:28:09.304 +0530|
Jae      |Pak              |2022-11-02 14:28:09.304 +0530|
Ranjit   |Varkey Chudukatil|2022-11-02 14:28:09.304 +0530|

SQL AdventureWorks Editor:

Practice Online

Contribute your code and comments through Disqus.

Previous: Add two days to each value in the OrderDate column.
Next: Get the differences between the maximum and minimum orderdate.

What is the difficulty level of this exercise?

Test your Programming skills with w3resource's quiz.

Share this Tutorial / Exercise on : Facebook and Twitter

SQL: Tips of the Day

Convert Timestamp to date in MySQL Query:

DATE_FORMAT(FROM_UNIXTIME(`user.registration`), '%e %b %Y') AS 'date_formatted'

Database: MySQL

Ref : https://bit.ly/3EJPnMQ