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?
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
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
ASKER
this is Oracle so I think I need the Concat etc.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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