7
$sql = "SELECT Kill FROM tbl_pvporderview";

Problem is that I end up with: Incorrect syntax near the keyword 'Kill'.

Because kill is a T-SQL command... any way to bypass it?

I can't change the column name because it's used by the software a lot and I cant change the software that's using the database.

So it simply fails if I use sqlserv to select data from that column. '' or "" wont help.

The complete statement would be:

$sql = "SELECT serial,Kill FROM tbl_pvporderview WHERE Kill > (?) ORDER BY Kill DESC ";
Paul White
95.4k30 gold badges440 silver badges689 bronze badges
asked Aug 23, 2012 at 12:03
0

2 Answers 2

14

If you want to use reserved words as table or column names, you have 2 options:

use brackets (the SQL-Server's way): SELECT [Kill]

or double-quotes* (the ANSI/ISO standard): SELECT "Kill"

Your whole statement would become:

SELECT [serial], [Kill] 
FROM tbl_pvporderview 
WHERE [Kill] > (?) 
ORDER BY [Kill] DESC ;

*: Of course, using double quotes (SELECT "Kill") would necessitate that QUOTED_IDENTIFIER is ON. You may encounter databases that the setting is still SET OFF.

answered Aug 23, 2012 at 12:11
0
9

Wrap the column name in square brackets:

$sql = "SELECT [Kill] FROM tbl_pvporderview"; 
answered Aug 23, 2012 at 12:10

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.