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

    Convert SQL Server Query To Access Query

    I am running this query in SQL Server so that only ONE employeeID shows the employee's salary, not each entry of the employeeID. This works as it should in SQL Server -> but for the life of me I can not discover how to re-write this in access.

    What would be the access query syntax to achieve this same result?


    Code:
    ;WITH data AS
    (
      SELECT [empName], [empID], TR = SUM([empSal]) OVER (PARTITION BY [empName]),
        r = ROW_NUMBER() OVER (PARTITION BY [empName] ORDER BY [empName])
      FROM employee
      WHERE [empID] IS NOT NULL
    ),
    All As
    (
    	Select
    	[empName]
        ,[empID]
        ,[PayrollDate]
    	,[DepositDate]
      FROM payroll  
      WHERE [empID] IS NOT NULL
    )
    SELECT 
    [empName] = aj.[empName]
    ,[empID] = aj.[empID]
    ,[payrolldate] = aj.[PayrollDate]
    ,[empSal] = ROUND(COALESCE(CASE r WHEN 1 THEN TR END, 0),0)
    FROM allempID aj
    LEFT JOIN data d
    ON aj.[empID] = d.[empID]
    GROUP BY aj.[empName], aj.[empID], aj.[PayrollDate]

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,549
    instead of translating it word for word,
    link the tables into access,
    and build the query you want, adding items until you get whats needed.

  3. #3
    rpeare is offline VIP
    Windows XP Access 2003
    Join Date
    Jul 2011
    Posts
    5,442
    how about some example tables and the data in them and what the result set you want is. I am not great with interpreting SQL to MS Access SQL without the access to a SQL server.

  4. #4
    jo15765's Avatar
    jo15765 is offline Expert
    Windows 10 Access 2013 64bit
    Join Date
    Nov 2010
    Location
    6 Feet Under
    Posts
    672
    My issue is using the row_number() function. Since I only want to update the ONE row - and not every row.
    I already have the tables linked into Access - I'll keep trying to build a query to get close.

    Could I just use an Access Pass through query for this since I am only selecting data?

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

Similar Threads

  1. Convert an Access 2010 DB to SQL Server DB
    By crowegreg in forum SQL Server
    Replies: 9
    Last Post: 05-01-2015, 04:45 PM
  2. Convert SQL Server Query to Access Query
    By Juan4412 in forum Queries
    Replies: 4
    Last Post: 04-16-2013, 12:41 PM
  3. Convert Access query to SQL Server query
    By mkallover in forum Queries
    Replies: 2
    Last Post: 05-13-2011, 06:20 AM
  4. Convert Access 07 ADO code to SQL Server Express 2008
    By jrdnoland in forum Programming
    Replies: 8
    Last Post: 04-14-2010, 05:57 PM
  5. Convert query sql server for Access
    By webtony in forum Queries
    Replies: 0
    Last Post: 06-23-2009, 02:46 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