Tuesday, December 2, 2008

SQL Server Problem Fixes

***************
1. Apostrophe issue in sql statement:

select * from business where name = 'Craig's List';

Above statement fails.

Use Below: Have to replace single apostrophe with two apostrophes.

select * from business where name = 'Craig''s List';

***************


***************
2. Sql statement errors out when there are spaces in column names.

"contact on contractor" is column in contractorconversion table.
"BUSINESS NAME" is another column in contractorconversion table.

To get around use: \"<>\" around the column name.

String sqlStmt = "select cc.\"contact on contractor\" as contact from contractorconversion cc, business b where b.name=cc.\"BUSINESS NAME\" and cc.\"BUSINESS NAME\"=";
***************

No comments: