SUBSTRING in where clause

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • maxamis4
    Recognized Expert Contributor
    • Jan 2007
    • 295

    SUBSTRING in where clause

    Hello folks,

    I have the following substring statement I am using but I want to filter by my substring, can anyone help


    Code:
    SELECT     last_name, SUBSTRING(alternate_identifier, 5, 2) AS Contractor
    FROM         ca_contact
    WHERE     (contact_type = 2308) AND (inactive <> 1)

    if i try this it fails with parsing errors


    Code:
    SELECT     last_name, SUBSTRING(alternate_identifier, 5, 2) AS Contractor
    FROM         ca_contact
    WHERE     (contact_type = 2308) AND (inactive <> 1) AND (Contractor = 'DC')
    thanks!
  • maxamis4
    Recognized Expert Contributor
    • Jan 2007
    • 295

    #2
    I found it thank you all for looking into this. Here is the what I found. The alias unlike oracle can not be referenced in the where clause. So to perform the calculation you must reference the table.[field]name followed by the formula. See below for example:

    Code:
    SELECT     last_name, SUBSTRING(alternate_identifier, 5, 2) AS Contractor
    FROM         ca_contact
    WHERE     (SUBSTRING(alternate_identifier, 5, 2) = 'DC')

    Comment

    Working...