Your organization stores shipping records in a SQL Server table named shipments with the columns order_id (INT), order_date (DATETIME), and delivery_date (DATETIME). To monitor logistics performance, you must create a field that shows how many calendar days each order spent in transit so the data team can later filter for any orders that took more than 7 days. You are not allowed to overwrite existing columns. Which SQL statement meets the requirement by creating an appropriate derived variable?
SELECT order_id, DATEDIFF(day, delivery_date, order_date) AS shipping_days FROM shipments;
SELECT order_id, delivery_date - order_date AS shipping_days FROM shipments;
SELECT order_id, DATEDIFF(day, order_date, delivery_date) AS shipping_days FROM shipments;
SELECT order_id, DATEADD(day, order_date, delivery_date) AS shipping_days FROM shipments;
A derived variable (also called a calculated or derived column) is a new field produced by applying an expression to existing columns and leaving the source data intact. In SQL Server the DATEDIFF() function returns the integer difference between two dates in the specified unit, so DATEDIFF(day, order_date, delivery_date) yields the total transit time for each row. Aliasing that result as shipping_days adds the new field without altering order_date or delivery_date, satisfying the scenario.
The second choice misuses DATEADD, which adds an interval to a date instead of computing a difference. The third choice subtracts two datetimes directly; in SQL Server this produces a decimal in days only when both are FLOAT expressions, not a clean integer, and it is unreliable across platforms. The fourth choice reverses the start and end arguments in DATEDIFF, resulting in negative values for on-time shipments and thus failing the business rule.
Ask Bash
Bash is our AI bot, trained to help you pass your exam. AI Generated Content may display inaccurate information, always double-check anything important.
How does the DATEDIFF function work in SQL Server?
Open an interactive chat with Bash
What is a derived column, and how is it different from a regular column?
Open an interactive chat with Bash
Why is DATEADD inappropriate for calculating date differences in this scenario?
Open an interactive chat with Bash
CompTIA Data+ DA0-002 (V2)
Data Acquisition and Preparation
Your Score:
Report Issue
Bash, the Crucial Exams Chat Bot
AI Bot
Loading...
Loading...
Loading...
Pass with Confidence.
IT & Cybersecurity Package
You have hit the limits of our free tier, become a Premium Member today for unlimited access.
Military, Healthcare worker, Gov. employee or Teacher? See if you qualify for a Community Discount.
Monthly
$19.99 $11.99
$11.99/mo
Billed monthly, Cancel any time.
$19.99 after promotion ends
3 Month Pass
$44.99 $26.99
$8.99/mo
One time purchase of $26.99, Does not auto-renew.
$44.99 after promotion ends
Save $18!
MOST POPULAR
Annual Pass
$119.99 $71.99
$5.99/mo
One time purchase of $71.99, Does not auto-renew.
$119.99 after promotion ends
Save $48!
BEST DEAL
Lifetime Pass
$189.99 $113.99
One time purchase, Good for life.
Save $76!
What You Get
All IT & Cybersecurity Package plans include the following perks and exams .