The sql table I have to work with contains backslashes in the column names. My current sql query:
$sql = "
SELECT
Mortgage_Number,
Sequence_Number,
Valuation_Date,
Open_Market_Value,
Reinstatement_Value,
Third_Party_Transaction_Type,
Asking_Price,
Forced_Sale_Price,
Property_Categpry,
Cracks_Y/N,
Underpinned_Y/N,
Adverse_Sales_Features_Y/N,
Reports_Required_Y/N,
Unfavorable_Y/N,
Added_By_User,
Added_Date,
Amend_By_User,
Amend_Date
FROM valuations
WHERE (Mortgage_Number = '$mortgage')
ORDER BY $criteria $direction
";
throws errors "Warning: mssql_query() [function.mssql-query]: message: Invalid column name 'Cracks_Y'. (severity 16) in ..."
How can get around this please?
Coping with backslashes when using sql queries
Moderator: General Moderators
-
alex.barylski
- DevNet Evangelist
- Posts: 6267
- Joined: Tue Dec 21, 2004 5:00 pm
- Location: Winnipeg
Re: Coping with backslashes when using sql queries
Don't use slashes in the first place.
You could maybe try the backtick operator around the column names.
[sql]SELECT * FROM TABLE WHERE `column` = 2[/sql]
You could maybe try the backtick operator around the column names.
[sql]SELECT * FROM TABLE WHERE `column` = 2[/sql]
Re: Coping with backslashes when using sql queries
Unfortuantely, I don't have a say in the column names as the table belongs to my boss.Hockey wrote:Don't use slashes in the first place.
You could maybe try the backtick operator around the column names.
[sql]SELECT * FROM TABLE WHERE `column` = 2[/sql]
However, I've just found that putting square brackets around the column names containing the back slashes solved the problem.
Thanks for replying.