CAST function question

A

Anne

Hello! I have the following SQL code:

SELECT AgtFirstName + ' ' + AgtLastName + ' has a projected income of ' +
CAST(Salary + (50000 * CommissionRate) AS CHARACTER)
AS ProjectedIncome
FROM Agents;

When I run it, I get the following message: Syntax Error(Missing Operator)
in query expression...
What am I doing wrong? Any help would be appreciated.
Thanks
 
M

Michel Walsh

If you are using Jet, instead of MS SQL Server, try:



SELECT AgtFirstName & ' ' & AgtLastName & ' has a projected income of ' &
(Salary + (50000 * CommissionRate))
AS ProjectedIncome
FROM Agents;



Vanderghast, Access MVP
 
A

Anne

So the CAST function doesn't work in Access 2007?
Thanks for your answer! I'll try it.
 
M

Michel Walsh

If you need explicit cast, it is probably like CDbl(), CDec(), CDate( ),
.... but Jet has much more 'automatic' casting than MS SQL Server does, so,
you are unlikely to need some explicit cast, at least, not when strings
concatenation is involved. You could need casting if you want to convert
from a string to a date, like:

CDate("Jan 1, 2009")


Vanderghast, Access MVP
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top