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:

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

SELECT
    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
ORDER BY LEFT(TRN_EndTime, 10) DESC, CUS_AccountNum, TLI_PK


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 GonzalezIT MGRAsked:
Who is Participating?
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 GonzalezIT MGRAuthor Commented:
0
Ryan ChongCommented:
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 %',
0
Ryan ChongCommented:
or:

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

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 GonzalezIT MGRAuthor Commented:
Great, this worked!

I really appreciate your help on this Ryan!
0
Mario GonzalezIT MGRAuthor Commented:
It worked!

Thanks!
0
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
Databases

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.