Results 1 to 4 of 4
  1. #1
    jo15765's Avatar
    jo15765 is offline Expert
    Windows 7 Access 2000
    Join Date
    Nov 2010
    Location
    6 Feet Under
    Posts
    672

    Running two SQL Statements

    I have one query, where I added the leading "0's" and the SQL statement I used to do this was:

    SELECT =Format([SKP B],"00000") AS Expr1
    FROM Sheet1;

    Then from this query, I want to combine the SKP B (with the leading zero's) and SKP A into one row in Access, and use the following SQL statement to do that:



    SELECT [Field1] & "-" & [Field2] AS Field1_Field2
    FROM Sheet1;

    The problem that I run into is that when I run the 2nd SQL statement the leading "O's" are dropped.

    I know that you can do this in two separate queries but I would much rather do it in one if that is possible.
    So my question is, is there a way to run two SQL statements in one query?
    OR is there a way for me to combine both of these statements into one SQL query?

  2. #2
    HiTechCoach's Avatar
    HiTechCoach is offline MS MVP - Access Expert
    Windows 7 Access 2010 (version 14.0)
    Join Date
    Jul 2010
    Location
    Oklahoma, USA
    Posts
    705
    Quote Originally Posted by jo15765 View Post

    SELECT [Field1] & "-" & [Field2] AS Field1_Field2
    FROM Sheet1;

    The problem that I run into is that when I run the 2nd SQL statement the leading "O's" are dropped.
    You are not telling it to add the leading zeros:

    Try:
    SELECT Format([Field1],"00000")[Field1] & "-" & Format([Field1],"00000")[Field2] AS Field1_Field2
    FROM Sheet1;
    Boyd Trimmell aka Hitechcoach
    Database Architect and Problem Solver
    Microsoft MVP - Access Expert
    25+ years specializing in Accounting, Inventory, and CRM systems
    "If technology doesn't work for people, then it doesn't work."

  3. #3
    jo15765's Avatar
    jo15765 is offline Expert
    Windows 7 Access 2000
    Join Date
    Nov 2010
    Location
    6 Feet Under
    Posts
    672
    When I try this code, I get a syntax error (missing operator)

  4. #4
    HiTechCoach's Avatar
    HiTechCoach is offline MS MVP - Access Expert
    Windows 7 Access 2010 (version 14.0)
    Join Date
    Jul 2010
    Location
    Oklahoma, USA
    Posts
    705
    Try:

    Code:
     
    SELECT Format([Field1],"00000") & "-" & Format([Field2],"00000")[Field2] AS Field1_Field2
    FROM Sheet1;
    Boyd Trimmell aka Hitechcoach
    Database Architect and Problem Solver
    Microsoft MVP - Access Expert
    25+ years specializing in Accounting, Inventory, and CRM systems
    "If technology doesn't work for people, then it doesn't work."

Please reply to this thread with any new information or opinions.

Similar Threads

  1. IIF statements?
    By staceyo in forum Queries
    Replies: 15
    Last Post: 09-28-2010, 08:45 AM
  2. SQL statements from VBA
    By John Southern in forum Programming
    Replies: 12
    Last Post: 05-16-2010, 01:07 PM
  3. Muliple If, Then Statements
    By jrockusa in forum Access
    Replies: 2
    Last Post: 12-06-2009, 11:06 PM
  4. IIF Statements
    By JDA2005 in forum Queries
    Replies: 8
    Last Post: 07-07-2009, 04:24 PM
  5. If statements
    By Ezeecopy in forum Access
    Replies: 0
    Last Post: 03-24-2009, 04:54 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums