error converting data type varchar to real

I have this code:

dbo.Invoice.InvoiceDate, COUNT(*) AS [Order QTY],

It works well in my View, however I want to build an expression from it like this:

dbo.Products.CartonCount * 'dbo.Inventory.BoxId:OrderQty' AS TotalPieces,

When I try to run it however I get this error:

error converting data type varchar to real

Can anyone help me understand why?

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.

Guy Hengel [angelIII / a3]Billing EngineerCommented:
where does this come from

in this expression, you had single quotes around it, which makes that it is interpreted as string:
dbo.Products.CartonCount * 'dbo.Inventory.BoxId:OrderQty' AS TotalPieces,
robynumAuthor Commented:
What I am trying to do is multiply the first field: dbo.Products.CartonCount by the second, but it is actually a COUNT of dbo.Inventory.BoxId with the ALIAS of OrderQTY.

Does this help?
Guy Hengel [angelIII / a3]Billing EngineerCommented:
I guess you want to do something like this:

select p.CartonCount * i.OrderQty
from dbo.Products p
join (select ii.product_id, count(*) orderqty from dbo.Inventory ii where ii.product_id = p.product_id ) as i
on i.Product_id = p.product_id
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.

robynumAuthor Commented:
Cool...Can I trouble you for two more questions?

1) I have a field that displays Date and Time (ex...3/9/2006 12:04:00 PM) I want to limit it to only show the Date. How?
2) I have another that shows my numbers out to a large number of Decimal places (ex...15.235432) I do not want to show the Decimals. How do I limit it?

Guy Hengel [angelIII / a3]Billing EngineerCommented:
1) use the convert(varchar(10), yourdatefield, xxxx) , where xxx is a style value, for example 101 (check out the convert and cast function in the books online about the possible values)
2) use the convert(numeric(10), yournumericfield) function, or to limit to 2 digits: convert(numeric(12,2), yournumericfield)

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
robynumAuthor Commented:
Cool...Thanks :)
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

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.