none
Error on SQL expression using vb.net RRS feed

  • Question

  •  

    I'm trying to run a sql on a table that contains a field that is a reserved word using vb.net, so I use [ ]  (can't remember how to spell it in english) on the field, but when I run it, it doesn't work. 

     

    Dim PBS As String = "SELECT RMS_MC.PBS_ISNCO.[type] FROM RMS_MC.PBS_ISNCO"

     

     

    To make sure the problem was the [ ]

     This Works:

    Dim PBS As String = "SELECT RMS_MC.PBS_ISNCO.SKU FROM RMS_MC.PBS_ISNCO"

     

     

    this one doesn.t

    Dim PBS As String = "SELECT RMS_MC.PBS_ISNCO.[SKU] FROM RMS_MC.PBS_ISNCO"

     

     

    I'm new in this world, so if someone could help me, I would appreciate!

    Friday, April 18, 2008 5:06 PM

All replies

  • When you fully qualify the column name with a table name the brackets are not required.
    Friday, April 18, 2008 7:03 PM
  • No, can't get this working, I'll paste all code below:

     

     

    Code Snippet

    Dim PBS As String =

    "SELECT

    RMS_MC.PBS_ISNCO.WH,

    RMS_MC.PBS_ISNCO.PRIMARY_SUPPLIER,

    RMS_MC.PBS_ISNCO.SKU,

    RMS_MC.PBS_ISNCO.NB_BUYER,

    RMS_MC.PBS_ISNCO.DEPT,

    RMS_MC.PBS_ISNCO.CLASS,

    RMS_MC.PBS_ISNCO.SUBCLASS,

    RMS_MC.PBS_ISNCO.AV_COST,

    RMS_MC.PBS_ISNCO.STOCK_ON_HAND,

    RMS_MC.PBS_ISNCO.[SOH Cxs],

    RMS_MC.PBS_ISNCO.STATUS,

    RMS_MC.PBS_ISNCO.SHIPPING_UNITS,

    RMS_MC.PBS_ISNCO.LOCATION,

    RMS_MC.PBS_ISNCO.type,

    RMS_MC.PBS_ISNCO.Comp,

    RMS_MC.PBS_ISNCO.QTY

    FROM RMS_MC.PBS_ISNCO"

     

     

     

    if I ignore the fields SOH Cxs, type and Comp, the query works perfectly.

    If I use brackets none will work:

     

    This Works, but if I use brackets it won't work:

    Code Snippet

    "SELECT

    WH,

    PRIMARY_SUPPLIER,

    SKU,

    NB_BUYER,

    DEPT

    FROM RMS_MC.PBS_ISNCO"

     

     


    With Brackets:

    Code Snippet

    "SELECT

    [WH],

    [PRIMARY_SUPPLIER],

    [SKU],

    [NB_BUYER],

    [DEPT]

    FROM RMS_MC.PBS_ISNCO"

     

     

     

     

    This doesn't Works 

    Code Snippet

    "SELECT

    WH,

    PRIMARY_SUPPLIER,

    SKU,

    NB_BUYER,

    DEPT

    SOH Cxs,

    FROM RMS_MC.PBS_ISNCO"

     

     

     

    Note that I can't change the souce database

    The server is ORACLE

    Tuesday, April 22, 2008 3:10 PM