SQL Scripts giving me an error

I have a POS server that I need to pull specific data so we can do data analysis, a friends of mine sent me this script, but we cannot figure out what is wrong with it. Here is the script:

SET @StartTime = '2015-06-07 12:00:00 AM'
SET @EndTime = '2015-06-07 11:59:59 PM'

    ISNULL(TRIM(CUS_AccountNum), '') AS 'Customer ID',
    CASE WHEN TRIM(CUS_LastName) IS NULL THEN 'NON MEMBER' ELSE TRIM(CUS_FirstName) + ' ' + TRIM(CUS_LastName) END AS 'Customer Name',
    TRIM(TLI_ScanCode) AS 'Item ID',
    TRIM(TLI_ReceiptAlias) AS 'Receipt Alias',
    TLI_Quantity AS 'Quantity',
    ITI_AverageCost * TLI_Quantity AS 'Extended_Cost',
    ISNULL(ExtendedBasePrice,TLI_Amount) AS 'Extended_Price',
    ISNULL(ExtendedBasePrice,TLI_Amount) - (ITI_AverageCost * TLI_Quantity) AS 'Profit',
    ROUND((Profit / Extended_Price) * 100, 2) AS 'Profit %',
    LEFT(TRN_EndTime, 10) AS 'DATE'
FROM v_Trans
WHERE TRN_EndTime >= @StartTime AND TRN_EndTime <= @EndTime
    AND TLI_LIT_FK IN ( 1, 15 )
    AND CUS_AccountNum IS NOT NULL

When I run this script, I get an error (attached file)

And it is only giving me about 150 rows of data.

Any help will be really appreciated.

Thank you,
Mario G.SupportAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Mario G.SupportAuthor Commented:
Ryan ChongBusiness Systems Analyst , ex-Senior Application EngineerCommented:
check the values for the field: Extended_Price, it seems contain 0 value which causing divided by zero error.

so u need a better handling for:

ROUND((Profit / Extended_Price) * 100, 2) AS 'Profit %',

and you can try something like this instead:

ROUND((Profit / case when Extended_Price = 0 then 1 else Extended_Price end) * 100, 2) AS 'Profit %',
Ryan ChongBusiness Systems Analyst , ex-Senior Application EngineerCommented:

case when Extended_Price = 0 then 0 else ROUND((Profit / Extended_Price ) * 100, 2) end AS 'Profit %',

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Mario G.SupportAuthor Commented:
Great, this worked!

I really appreciate your help on this Ryan!
Mario G.SupportAuthor Commented:
It worked!

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.