Results 1 to 9 of 9

Thread: sql question

  1. #1

    Thread Starter
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    sql question

    ugh.. i can't remember this.. but when you do a join in an sql satatement and if you don't get a match on the join field how do you display a different value in its place?? so I have 2 tables.. tblCoaching and tblEmployees

    so i have a stamement like this
    Code:
    SELECT tblCoaching.RecordID, tblCoaching.UserID, tblCoaching.EntererID, tblEmployees.NameLastFirst
    FROM tblCoaching LEFT JOIN tblEmployees ON tblCoaching.EntererID = tblEmployees.UserId
    but if the user was deleted from tblEmployees I want to display just the userid from the coaching table... how do i do this again?? i thoguht it was with a null check or something

  2. #2
    Fanatic Member
    Join Date
    Feb 2002
    Location
    SE England
    Posts
    732
    What DB type is it? (SQL server/ Access)
    Leather Face is comin...


    MCSD

  3. #3
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687
    It doesn't matter the SQL type.....\
    Matt, this is what you are looking for:
    Code:
    SELECT tblCoaching.RecordID, tblCoaching.UserID, tblCoaching.EntererID, tblEmployees.NameLastFirst
    FROM tblCoaching LEFT JOIN tblEmployees ON tblCoaching.EntererID = tblEmployees.UserId
    WHERE tblEmployees.UserID IS NULL
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  4. #4
    Frenzied Member McGenius's Avatar
    Join Date
    Jan 2003
    Posts
    1,199
    This might be what you're looking for:

    SELECT tc.RecordID, tc.UserID, tc.EntererID, tc.NameLastFirst
    FROM tblCoaching tc, tblEmployees te
    WHERE tc.EntererID = te.UserId
    McGenius

  5. #5
    Fanatic Member
    Join Date
    Feb 2002
    Location
    SE England
    Posts
    732
    Yes it does matter because to display a value in place of a NULL you are going to have to do some kind of replace, and the way this is done varies depending on the DB....

    Your joins don't help as he has already got this far...
    Leather Face is comin...


    MCSD

  6. #6
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687
    D'OH! I misread what he asked..... OK, I don't know the answer for Access, but in SQL Server, use ISNULL(FieldName, Value to use then FieldName is NULL)
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  7. #7

    Thread Starter
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373
    its sql server 2k

  8. #8

    Thread Starter
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373
    Originally posted by techgnome
    D'OH! I misread what he asked..... OK, I don't know the answer for Access, but in SQL Server, use ISNULL(FieldName, Value to use then FieldName is NULL)
    thanks.. i think that is what i am looking for

  9. #9

    Thread Starter
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373
    yup got it working now... i thought it was isnull.. but my brain was fused to VB for a second and I forgot that you send a second parameter to replace the null value

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