SQL conversion failed

I am trying to get a sum of some column., but getting the conversion error message, the column promoCodeAmount is type varchar, and I am converting it to int but getting an error messsage  

Conversion failed when converting the varchar value '62.9' to data type int.

DECLARE @startDt DATETIME,@endDt DATETIME,@stateID INT
SET @startDt = '06/30/2015'
SET @endDt = '07/01/2015'
SET @stateID = 1
		SELECT  'Promo' AS description,sum(convert(int,NULLIF(O.promoCodeAmount,0))) as tSum,COUNT(convert(int,NULLIF(O.promoCodeAmount,0))) as cnt
				from trans T  
				inner join orders O on O.orderKey = T.orderKey
				
				WHERE  T.TransDate BETWEEN @startDt AND @endDt 
                            and LI.officeStateKey = @stateID 
                            
                            AND not EXISTS (
                                    SELECT count(1) from orders_paymentPlan OPP
                                    where opp.orderKey = o.orderKey
                                    and opp.paymentDate BETWEEN @startDt AND @endDt
                                    Having(COUNT(OPP.orderKey)) > 1
                                )
                            
					GROUP BY description

Open in new window

LVL 19
erikTsomikSystem Architect, CF programmer Asked:
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.

John Gates, CISSPSecurity ProfessionalCommented:
Have you tried decimal??
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
erikTsomikSystem Architect, CF programmer Author Commented:
I did still does not work
0
Jim HornMicrosoft SQL Server Developer, Architect, and AuthorCommented:
Just for kicks and giggles, run this
SELECT promoCodeAmount 
FROM the_table_name
WHERE ISNUMERIC(promoCodeAmount) = 0

Open in new window


Casting a 62.9 to an int would normally return 62, the part before the decimal, so perhaps there is something else going on here.
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

erikTsomikSystem Architect, CF programmer Author Commented:
Just solved it

		DECLARE @startDt DATETIME,@endDt DATETIME,@stateID INT
SET @startDt = '06/30/2015'
SET @endDt = '07/01/2015'
SET @stateID = 1
		SELECT  'Promo' AS description,
		sum(cast(isnull(O.promoCodeAmount,0) as decimal(12,6))) as tSum,
		COUNT(cast(isnull(O.promoCodeAmount,0) as decimal(12,6))) as cnt
				from trans T  
				inner join orders O on O.orderKey = T.orderKey
				
				inner join lineitems LI on LI.orderKey = O.orderKey
				WHERE O.void = 'N'AND T.TransDate BETWEEN @startDt AND @endDt 
                            and LI.officeStateKey = @stateID 
                            and T.validated <> 'N'
                            AND not EXISTS (
                                    SELECT count(1) from orders_paymentPlan OPP
                                    where opp.orderKey = o.orderKey
                                    and opp.paymentDate BETWEEN @startDt AND @endDt
                                    Having(COUNT(OPP.orderKey)) > 1
                                )
                              
					GROUP BY description

Open in new window

0
John Gates, CISSPSecurity ProfessionalCommented:
Glad that sorted it!  Have a good weekend :)

-D-
0
PortletPaulfreelancerCommented:
It was the change to ISNULL() that fixed this I believe ...
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
Query Syntax

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.