Link to home
Start Free TrialLog in
Avatar of sbornstein2
sbornstein2

asked on

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?
Avatar of Jason Scolaro
Jason Scolaro
Flag of United States of America image

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
Avatar of sbornstein2
sbornstein2

ASKER

string SQL = "Select ACCOUNT_NUMBER, ACCOUNT_NAME, CONCAT(ACCOUNT_NUMBER || '-' || ACCOUNT_NAME) AS ACCTCONCAT from " +
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
this is Oracle so I think I need the Concat etc.
ASKER CERTIFIED SOLUTION
Avatar of Jason Scolaro
Jason Scolaro
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial