Question

I am trying to fix this query:

  1. I have an update query.

    UPDATE controll_SZHEAD14 
    LEFT JOIN [outgoing] ON controll_SZHEAD14.sa_code = [outgoing].Account 
    SET [outgoing].Account = controll_SZHEAD14.sa_code, [outgoing].Buyer = controll_SZHEAD14.sa_buyername, [outgoing].startdate = controll_SZHEAD14.sa_date, [outgoing].Finance = controll_SZHEAD14.sa_tedat, [outgoing].maxdate = controll_SZHEAD14.sa_esdat, [outgoing].[25alap] = controll_SZHEAD14.sa_summary
    WHERE (((controll_SZHEAD14.sa_code)>"BA14/01997"));
    

    So if I run this query above, than refresh my data, but only from BA14/01997 till now. So in this example this will refresh 66 row. (66 row affected)

  2. I have this simple select SQL:

    SELECT TOP 1 Account FROM [outgoing] ORDER BY Account DESC;
    

    If I run this above I got the last account, in this example:BA14/01997

  3. So I would like to take this two query "update+select" together.

    UPDATE controll_SZHEAD14 
    LEFT JOIN [outgoing] ON controll_SZHEAD14.sa_code = [outgoing].Account 
    SET [outgoing].Account = controll_SZHEAD14.sa_code, [outgoing].Buyer = controll_SZHEAD14.sa_buyername, [outgoing].startdate = controll_SZHEAD14.sa_date, [outgoing].Finance = controll_SZHEAD14.sa_tedat, [outgoing].maxdate = controll_SZHEAD14.sa_esdat, [outgoing].[25alap] = controll_SZHEAD14.sa_summary
    WHERE (((controll_SZHEAD14.sa_code)>"SELECT TOP 1 Account FROM [outgoing] GROUP BY Account DESC;")); 
    

    The above query does not work properly. When I run, I got 0 row affected, but I expect the same as the first update query.

Any idea how to fix this?

Was it helpful?

Solution

Enclose the SELECT statement in ( ) brackets

UPDATE controll_SZHEAD14 
LEFT JOIN [outgoing] 
ON controll_SZHEAD14.sa_code = [outgoing].Account 
SET [outgoing].Account = controll_SZHEAD14.sa_code, 
    [outgoing].Buyer = controll_SZHEAD14.sa_buyername, 
    [outgoing].startdate = controll_SZHEAD14.sa_date, 
    [outgoing].Finance = controll_SZHEAD14.sa_tedat, 
    [outgoing].maxdate = controll_SZHEAD14.sa_esdat, 
    [outgoing].[25alap] = controll_SZHEAD14.sa_summary 
WHERE controll_SZHEAD14.sa_code > (
                                    SELECT TOP 1 Account 
                                    FROM [outgoing] 
                                    ORDER BY Account DESC
                                  );
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top