keyword as a field name

  • hi

    i have created a table orders, in that i have given one column name order, which is a keyword in sqlserver, actually the table contains 5 fields. now when i want to insert the data in table only in order field like

    insert into orders (order) values('xyz').

    it is giving the error message incorrect syntax near the keyword order.

    is it possible to insert the data without modifying the filed name.

    Actually i am giving this insert statement from vb.net. so if possible give the vb.net statement also.

    Thanking you,

    Thiru.

  • It is actually not the best idea to name columns with reserved words. You should really change this.

    --
    Frank Kalis
    Microsoft SQL Server MVP
    Webmaster: http://www.insidesql.org/blogs
    My blog: http://www.insidesql.org/blogs/frankkalis/[/url]

  • Avoid reserved words, you should.

    If avoidable it is not, then seek the power of the proper delimiter. Result desired, square brackets will provide:

    select [order] from yourtable

    A true jedi will avoid reserved words. Sometimes even Yoda uses them, however. Perfect, he is not.

    Even "Dummy", a reserved word in T-SQL is! Perhaps for those who choose to follow the dark side!? hmm?

  • Yoda you ROCK! you must be the real one!

    Was getting the above error on my DespLn table on an attribute called LineNo when reporting in Excel (ODBC) edited the SQL so it looked like 'select blah despln.[lineno] ...' and it worked!

    BUT, I could swear this table (quite an important one in our reporting system) was working before, some users set-up their own queries, does anyone  know why the error would start to come up?

    If we wrote a Stored Proc that was called LineNo?

    Thanks,

    Ian

  • The error started coming up because a reserved word was used, it's as simple as that.

    By using reserved words, it's not a question of if, but rather when your code will break. There is a reason they are called 'reserved', you know

    /Kenneth

Viewing 5 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic. Login to reply