How do I correct: Conversion failed when converting the varchar value 'CashDiscount' to data type smallint

I have identified 3 columns with same issue in my view.

Conversion failed when converting the varchar value 'CashDiscount' to data type smallint

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.

Jim HornMicrosoft SQL Server Developer, Architect, and AuthorCommented:
Copy the SQL behind your view and paste it into this question.
rhservanAuthor Commented:
This is the code where the problem is:

dbo.paymentypedim AS pt ON pt.PaymentTypeKey = d.PaymentTypeCode

PaymentTypeKey(smallint) and needs to convert to text to work with d.PaymentTypeCode(varchar)

How do I convert the PaymentTypeKey to text in the view?

rhservanAuthor Commented:
TOP (100) PERCENT t.DateKey,
(s.LotKey, 0) AS LotKey, CASE WHEN t .IsVoid = 1 THEN d .PaymentAmount ELSE 0 END AS VoidAmount,
CASE WHEN t .IsNoCharge = 1 THEN d .PaymentAmount ELSE 0 END AS NoCharge,
CASE WHEN pt.IsCash = 1 AND pt.IsCreditCard = 0 THEN d .PaymentAmount ELSE 0 END AS CashAmount,
CASE WHEN pt.IsCash = 0 AND pt.IsCreditCard = 1 THEN d .PaymentAmount ELSE 0 END AS CreditCardAmount,
p.TotalPaymentAmount AS FinalTicketAmount, t.TicketNumber
dbo.SourceSystemLot AS s INNER JOIN
dbo.LotDim AS l ON s.LotKey = l.LotKey INNER JOIN
dbo.CityDim AS c ON c.CityKey = l.CityKey LEFT OUTER JOIN
dbo.TicketFact AS t ON t.LocationID = s.LocationID LEFT OUTER JOIN
dbo.PaymentFact AS p ON t.TicketKey = p.TicketKey INNER JOIN
dbo.PaymentDetail AS d ON d.PaymentKey = p.PaymentKey LEFT OUTER JOIN
dbo.PaymentTypeDim AS pt ON pt.PaymentTypeKey = d.PaymentTypeCode
WHERE (s.SourceSystemKey = 2)
dbo.paymentypedim AS pt ON CAST(pt.PaymentTypeKey as varchar) = d.PaymentTypeCode

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
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
Microsoft SQL Server 2008

From novice to tech pro — start learning today.