Operand '-' cannot be applied to operands of type String

I have a string that I am using to create a query to a database.  In the string I am doing a concatenate and using "-" and also tried '-' still same error.  Trying to place a dash in between two things.  Any idea?
sbornstein2Asked:
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.

Jason ScolaroCommented:
Hi sbornstein2,

Can you show us what you have?  If I understand what you're trying to do.. it should look something like:

VB.NET:  objComm.CommandText = "SELECT * FROM TableName WHERE FieldA = '" & MyString & "-" & MyOtherString & "'"
C#:  objComm.CommandText = "SELECT * FROM TableName WHERE FieldA = '" + MyString + "-" + MyOtherString + "'";

-- Jason
sbornstein2Author Commented:
string SQL = "Select ACCOUNT_NUMBER, ACCOUNT_NAME, CONCAT(ACCOUNT_NUMBER || '-' || ACCOUNT_NAME) AS ACCTCONCAT from " +
Jason ScolaroCommented:
Do this...
string SQL = "Select ACCOUNT_NUMBER, ACCOUNT_NAME, CAST(ACCOUNT_NUMBER as varchar) + '-' + ACCOUNT_NAME) AS ACCTCONCAT from " +

I'm assuming ACCOUNT_NAME is also a varchar, otherwise you might need to CAST it as well.  Good luck!

-- Jason
sbornstein2Author Commented:
this is Oracle so I think I need the Concat etc.
Jason ScolaroCommented:
I just tried it on our Oracle system... this should work:
string SQL = "Select ACCOUNT_NUMBER, ACCOUNT_NAME, ACCOUNT_NUMBER || '-' || ACCOUNT_NAME AS ACCTCONCAT from " +

If you continue to have problems with it though, you might want to ask in the Oracle TA, there might be better expertise there... although I think you will find the above solution should work...

Good luck!
-- Jason

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
ASP.NET

From novice to tech pro — start learning today.