1. Computer problem? Tech Support Guy is completely free -- paid for by advertisers and donations. Click here to join today! If you're new to Tech Support Guy, we highly recommend that you visit our Guide for New Members.

SQL & ASP Where problem

Discussion in 'Software Development' started by gbrandwood, Nov 19, 2001.

Thread Status:
Not open for further replies.
  1. gbrandwood

    gbrandwood Thread Starter

    Joined:
    Jan 4, 2000
    Messages:
    137
    Dear all

    I have the following code in my ASP page:

    Set objCon=Server.CreateObject("ADODB.Connection")
    objCon.Open "hrpolicies"
    Set recCon=Server.CreateObject("ADODB.Recordset")
    SQL=SQL + "SELECT DISTINCT Category"
    SQL=SQL + " FROM tblPolicies"
    SQL=SQL + " WHERE Category != 'NONE'"
    SQL=SQL + " ORDER BY Category DESC;"
    recCon.Open SQL,objCon,3

    I want the page to return distinct records from the category field, from the table called tblPolicies, but only where the category field is not set to NONE. E.g. if the category field is set to HR, it will list HR. NONE is a value a user will have typed in. It is not null.

    If I change my code so that it says show records where the category fields does contain the word NONE, i.e.:

    Set objCon=Server.CreateObject("ADODB.Connection")
    objCon.Open "hrpolicies"
    Set recCon=Server.CreateObject("ADODB.Recordset")
    SQL=SQL + "SELECT DISTINCT Category"
    SQL=SQL + " FROM tblPolicies"
    SQL=SQL + " WHERE Category = 'NONE'"
    SQL=SQL + " ORDER BY Category DESC;"
    recCon.Open SQL,objCon,3

    The page works fine. So I'm confused as to where am I going wrong?

    Any help would be appreciated.

    Regards

    Gareth
     
  2. gbrandwood

    gbrandwood Thread Starter

    Joined:
    Jan 4, 2000
    Messages:
    137
    Opps! After spending ages wondering what was up my code - I realised that changing my where statement from:

    SQL=SQL + " WHERE Category != 'NONE'"

    to:

    SQL=SQL + " WHERE Category <> 'NONE'"

    did the trick!

    Sorry to have bothered all you nice people.

    Regards

    Gareth
     
As Seen On
As Seen On...

Welcome to Tech Support Guy!

Are you looking for the solution to your computer problem? Join our site today to ask your question. This site is completely free -- paid for by advertisers and donations.

If you're not already familiar with forums, watch our Welcome Guide to get started.

Join over 733,556 other people just like you!

Thread Status:
Not open for further replies.

Short URL to this thread: https://techguy.org/58998

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice