Results 1 to 7 of 7

Thread: SQL 2005 CROSS JOIN Query help

  1. #1
    Join Date
    Oct 2011
    Posts
    5

    SQL 2005 CROSS JOIN Query help

    Hello, I have a SQL 2005 Database with two tables that I need to CROSS JOIN in an update query.

    The first table is BADGE and column to update is TYPE.

    The problem I am having is the part where I need to reference another table UDFEMP column PERSONNELTYPE

    so the basic idea is:

    update BADGE set TYPE= 16 where TYPE = 66 if udfemp.personneltype = 'NONE'

  2. #2
    Join Date
    Nov 2002
    Location
    New Jersey, USA
    Posts
    3,932
    update BADGE set TYPE= 16
    FROM BADGE
    JOIN UDFEMP
    ON ... <-- your join statement here-->
    where BADGE.TYPE = 66 udfemp.personneltype = 'NONE'

  3. #3
    Join Date
    Oct 2011
    Posts
    5

    Join Statement

    How would I determine what my JOIN Statement would be?


    ON ... <-- your join statement here-->

  4. #4
    Join Date
    Oct 2011
    Posts
    5
    [QUOTE=bmallett1;129791]How would I determine what my JOIN Statement would be?

    Yes there is a table that joins the two. It is the EMP table and column is ID. If I build a View with the three tables I get:

    dbo.EMP INNER JOIN
    dbo.UDFEMP ON dbo.EMP.ID = dbo.UDFEMP.ID CROSS JOIN
    dbo.BADGE

  5. #5
    Join Date
    Oct 2011
    Posts
    5
    [QUOTE=bmallett1;129792]
    Quote Originally Posted by bmallett1 View Post
    How would I determine what my JOIN Statement would be?

    Yes there is a table that joins the two. It is the EMP table and column is ID. If I build a View with the three tables I get:

    dbo.EMP INNER JOIN
    dbo.UDFEMP ON dbo.EMP.ID = dbo.UDFEMP.ID CROSS JOIN
    dbo.BADGE
    How would we add the JOIN to the query?

  6. #6
    Join Date
    Oct 2011
    Posts
    5
    [QUOTE=bmallett1;129793]
    Quote Originally Posted by bmallett1 View Post

    How would we add the JOIN to the query?
    The column that matches between BADGE & EMP is BADGE.EMPID with EMP.ID

  7. #7
    Join Date
    Nov 2002
    Location
    New Jersey, USA
    Posts
    3,932
    CROSSJOIN is a different beast, it will give you cartesian product. Try this

    update BADGE set TYPE= 16
    FROM BADGE
    JOIN UDFEMP
    ON BADGE.EMPID=EMP.ID
    where BADGE.TYPE = 66 udfemp.personneltype = 'NONE'

Posting Permissions

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