• Visitors can check out the Forum FAQ by clicking this link. You have to register before you can post: click the REGISTER link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below. View our Forum Privacy Policy.
  • Want to receive the latest contracting news and advice straight to your inbox? Sign up to the ContractorUK newsletter here. Every sign up will also be entered into a draw to WIN £100 Amazon vouchers!

Reply to: Access SQL

Collapse

You are not logged in or you do not have permission to access this page. This could be due to one of several reasons:

  • You are not logged in. If you are already registered, fill in the form below to log in, or follow the "Sign Up" link to register a new account.
  • You may not have sufficient privileges to access this page. Are you trying to edit someone else's post, access administrative features or some other privileged system?
  • If you are trying to post, the administrator may have disabled your account, or it may be awaiting activation.

Previously on "Access SQL"

Collapse

  • Sockpuppet
    replied
    Doh.

    I used NotIn instead of Not In

    Cheers fella, need to get back to warehouses or trucking. All this access and SQL is starting to make me a sad boy.

    Leave a comment:


  • TheFaQQer
    replied
    Originally posted by Sockpuppet View Post
    Anyone know a quick an dirty way to reverse this.

    Code:
    select * from [IS] inner join (SELECT DISTINCT Mapping.Mapping As HMapping FROM Mapping) Map on [IS].HMapping=Map.HMapping;
    Code:
    SELECT * [IS] WHERE HMapping IN  (SELECT DISTINCT Mapping.Mapping As HMapping FROM Mapping);
    Instead of it selecting records are are found in the Mapping table I am looking to make it select records that are not equal to the mapping in the mapping table.

    Is there such a function as NotIn for Access?

    Sockpuppet in "i'm not an IT guy" mode.
    Try "NOT IN" - think it's there in Access, since it's a SQL thing.

    Leave a comment:


  • Sockpuppet
    replied
    Anyone know a quick an dirty way to reverse this.

    Code:
    select * from [IS] inner join (SELECT DISTINCT Mapping.Mapping As HMapping FROM Mapping) Map on [IS].HMapping=Map.HMapping;
    Code:
    SELECT * [IS] WHERE HMapping IN  (SELECT DISTINCT Mapping.Mapping As HMapping FROM Mapping);
    Instead of it selecting records are are found in the Mapping table I am looking to make it select records that are not equal to the mapping in the mapping table.

    Is there such a function as NotIn for Access?

    Sockpuppet in "i'm not an IT guy" mode.

    Leave a comment:


  • Weltchy
    replied
    For an even more obscure way of doing this, giving you the much needed little to no performance gain whatsoever (Could even be slower), you could have used a select into a temporary table and then joined on the required temporary table.

    Remember, extra code for no performance gain = The contractors holy grail, making you look like you've had to do lots of work when in fact you've done little.

    Leave a comment:


  • Sockpuppet
    replied
    Cool. Thanks for the help guys

    Leave a comment:


  • lilelvis2000
    replied
    Originally posted by Sockpuppet View Post
    Thanks for the reply...was suprisingly easy in the end.

    Code:
    SELECT i.CE_Identifier, i.EQOS_Ref, i.UK_Prod_Description, i.IS_Line_Status,
     i.UK_CE_Only, i.UK_Prod_Type, i.UK_Season, i.Line_Status, i.UK_TPN,
    i.Product_Barcode_EAN, i.ITF_14, i.Case_Size, i.Brand, i.UK_Performer,
    i.VPN, i.Supplier_Name, i.Supplier_Number, i.IS_Factory, i.Port, i.COO,
    i.Depot_Stream, i.Delivery_Method, i.Case_Width, i.Case_Length, 
    i.Case_Height, i.COP, i.Unit_1CP, i.Retek_Cost, i.FCL_Insurance, 
    i.FCL_Freight, i.FCL_Basic, i.IS_Admin_Cost, i.Duty, i.FCL_ELC, 
    i.Landed_Unit_Cost, i.UK_ROS FROM [IS] As i WHERE 
    (((i.Country)=""" & CountryCode & """) AND ((i.COP) <> """") AND 
    HMapping IN (SELECT DISTINCT Hierarchy.Mapping As HMapping 
    FROM Hierarchy WHERE (((Hierarchy.Department_Number)=" & DepNum & ") 
    AND ((Hierarchy.Section_Number)=" & SectionNum & "))));
    You could also have created your Select Distinct as a query and then performed a join from HMapping to it. similar to

    select .....blah.... from [IS] inner join (select distinct HMapping ...blah...) Map on [IS].HMapping=Map.HMapping;

    Cheers.

    Leave a comment:


  • Sockpuppet
    replied
    Thanks for the reply...was suprisingly easy in the end.

    Code:
    SELECT i.CE_Identifier, i.EQOS_Ref, i.UK_Prod_Description, i.IS_Line_Status,
     i.UK_CE_Only, i.UK_Prod_Type, i.UK_Season, i.Line_Status, i.UK_TPN,
    i.Product_Barcode_EAN, i.ITF_14, i.Case_Size, i.Brand, i.UK_Performer,
    i.VPN, i.Supplier_Name, i.Supplier_Number, i.IS_Factory, i.Port, i.COO,
    i.Depot_Stream, i.Delivery_Method, i.Case_Width, i.Case_Length, 
    i.Case_Height, i.COP, i.Unit_1CP, i.Retek_Cost, i.FCL_Insurance, 
    i.FCL_Freight, i.FCL_Basic, i.IS_Admin_Cost, i.Duty, i.FCL_ELC, 
    i.Landed_Unit_Cost, i.UK_ROS FROM [IS] As i WHERE 
    (((i.Country)=""" & CountryCode & """) AND ((i.COP) <> """") AND 
    HMapping IN (SELECT DISTINCT Hierarchy.Mapping As HMapping 
    FROM Hierarchy WHERE (((Hierarchy.Department_Number)=" & DepNum & ") 
    AND ((Hierarchy.Section_Number)=" & SectionNum & "))));

    Leave a comment:


  • DaveB
    replied
    Originally posted by Sockpuppet View Post
    Right trying to do this and it is annoying me.

    Got 2 queries.

    Code:
    SELECT DISTINCT Hierarchy.Mapping
    FROM Hierarchy
    WHERE (((Hierarchy.Department_Number)=170) AND ((Hierarchy.Section_Number)=510));
    and

    Code:
    SELECT *
    FROM [IS]
    WHERE ((([IS].Country)='CZ') AND (([IS].HMapping)="H11AA"));
    The first returns several records and I need to select from the second based on these like having HMapping = x Or Y OR z Or etc

    I've tried a join from HMapping to Mapping (table relationships) but it returns one record from the IS for each mapping i.e. each line about 1000 times.

    I think I need a nested SQL statement but can for the life of me think where to start on this one.

    If that fails I'll have to store the items in an array and formulate a sql statement but a nested SQL will be far easier?

    Ideas?

    SQL isnt my strong point but would a CASE statement work for this?

    Code:
    CASE
      WHEN booleanExpression1 THEN result1
      WHEN booleanExpression2 THEN result2
      ...
      WHEN booleanExpressionN THEN resultN
      
      [
        ELSE elseResult
      ]
    END

    Or somthing similar?

    Leave a comment:


  • Sockpuppet
    started a topic Access SQL

    Access SQL

    Right trying to do this and it is annoying me.

    Got 2 queries.

    Code:
    SELECT DISTINCT Hierarchy.Mapping
    FROM Hierarchy
    WHERE (((Hierarchy.Department_Number)=170) AND ((Hierarchy.Section_Number)=510));
    and

    Code:
    SELECT *
    FROM [IS]
    WHERE ((([IS].Country)='CZ') AND (([IS].HMapping)="H11AA"));
    The first returns several records and I need to select from the second based on these like having HMapping = x Or Y OR z Or etc

    I've tried a join from HMapping to Mapping (table relationships) but it returns one record from the IS for each mapping i.e. each line about 1000 times.

    I think I need a nested SQL statement but can for the life of me think where to start on this one.

    If that fails I'll have to store the items in an array and formulate a sql statement but a nested SQL will be far easier?

    Ideas?
Working...
X