CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Jun 2010
    Posts
    56

    SQL Select Statement

    I'm trying to pass a SQL statement through C# but my SQL statement needs quotes around a table since the name of the table is also a proper SQL command(which I have no control over).

    Looking at MSDN I tried the following two methods but.

    string sqlSELECT = @"select * FROM tableNAME.""SELECT"";

    string sqlSELECT = "select * FROM tableNAME./"SELECT/"";

    The problem is that both of these statements above leave in slashes.

  2. #2
    Join Date
    Mar 2004
    Location
    Prague, Czech Republic, EU
    Posts
    1,701

    Re: SQL Select Statement

    They should be backslashes...
    Code:
    string sqlSELECT = @"select * FROM tableNAME.\"SELECT\"";
    ... but the sql looks weird at all.
    • Make it run.
    • Make it right.
    • Make it fast.

    Don't hesitate to rate my post.

  3. #3
    Join Date
    Jun 2010
    Posts
    56

    Re: SQL Select Statement

    Whoops meant to put backslashes in but still the end result will come out with slashes in the SQL statement.

  4. #4
    Join Date
    Jul 2008
    Location
    WV
    Posts
    5,362

    Re: SQL Select Statement

    use [ ] around reserved words or names that contain spaces in your sql string


    Select * from [Select] where [User Name] = ....
    Always use [code][/code] tags when posting code.

  5. #5
    Join Date
    Jun 2010
    Posts
    56

    Re: SQL Select Statement

    Thats what their called, reserved words, had I remember that would have solved this without assistance.

    Thanks you though.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured