A data analyst is working with a 'product_sku' column that contains values like 'SKU-A483B', 'ITEM-C912D', and 'PROD-B556E'. The prefixes ('SKU-', 'ITEM-', 'PROD-') vary in length, but the desired product code is always the sequence of characters that follows the hyphen. The analyst needs to create a new column containing only the product code. Which pair of string functions is most suitable for reliably extracting the product code from each entry?
The correct option combines SUBSTRING and CHARINDEX. The CHARINDEX function (or similar functions like LOCATE or INSTR in other SQL dialects) is used to find the starting position of the hyphen ('-'), which acts as a delimiter. The SUBSTRING function then extracts the part of the string that starts at the position immediately after the hyphen. This method is robust because it does not depend on the length of the prefix, making it suitable for inconsistent data.
The RIGHT and LEN functions are incorrect because RIGHT requires a fixed number of characters to extract. While this could be calculated using LEN and CHARINDEX, the pair of functions by itself is not the most direct or reliable solution for handling variable-length prefixes.
The REPLACE and LEFT functions are incorrect. Using REPLACE would require knowing and individually replacing every possible prefix (e.g., 'SKU-', 'ITEM-'), which is inefficient. LEFT would extract the prefix itself, not the desired code.
The TRIM and CONCAT functions are incorrect. TRIM removes leading and trailing whitespace, which is not the issue in this scenario. CONCAT is used to combine strings, which is the opposite of the required extraction task.
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.
What does the `CHARINDEX` function do?
Open an interactive chat with Bash
How does `SUBSTRING` work in SQL?
Open an interactive chat with Bash
Why is `SUBSTRING` combined with `CHARINDEX` in this scenario?
Open an interactive chat with Bash
CompTIA Data+ DA0-002 (V2)
Data Analysis
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 .