ianbrown76
Technical User
Hi
I have a table in my database that contains Orders, I recieve a list of Cancellations [of customers] that I have to then use to update the list of Orders to mark that certain customer products have been cancelled.
In order to find just the Orders that have to be marked as cancelled on the Orders table I import the list of customers into a table and run a query.
As one customer may have placed more than one order and the list I recieve only contains the Customer, I get 'duplicates' in the subsequent query and cannot run an 'update' query on all the records that occur as I couldn't be sure which order I need to cancel.
I have tried to do a count from my first query on the number of times a customer occurs and then link it back to a query which is same as the first but only where the customer occurs once, unfortunately I get an error telling me that the query is not updateable.
I've attempted to create a subquery [in SQL] to remedy the problem but I've not come accross the EXISTS word before, when the query runs it does not appear to do what I'd like, this is the SQL that I've created inorder to display only customers from my 'cancellations list' who occur only once on the 'orders' table:-
SELECT [Canc list].[ACCOUNT NUMBER]
FROM [canc list]
WHERE Exists
(SELECT ([canc list].[ACCOUNT NUMBER]), Count([canc list].[ACCOUNT NUMBER])
FROM [Orders] RIGHT JOIN [canc list] ON [orders].[Account Number] = [canc list].[ACCOUNT NUMBER]
WHERE ([orders].[Not Converted/Cancelled]) In ('c','j')
GROUP BY [canc list].[ACCOUNT NUMBER]
HAVING count ([canc list].[account number]) = 1)
ORDER BY [canc list].[ACCOUNT NUMBER];
I could copy counts etc into more tables but as I won't be updating the orders myself I was hoping for some kind of user friendly method for my colleagues to use.
Does anybody have any suggestions as to how to get around the problem?
Many Thanks in Advance
Ian
I have a table in my database that contains Orders, I recieve a list of Cancellations [of customers] that I have to then use to update the list of Orders to mark that certain customer products have been cancelled.
In order to find just the Orders that have to be marked as cancelled on the Orders table I import the list of customers into a table and run a query.
As one customer may have placed more than one order and the list I recieve only contains the Customer, I get 'duplicates' in the subsequent query and cannot run an 'update' query on all the records that occur as I couldn't be sure which order I need to cancel.
I have tried to do a count from my first query on the number of times a customer occurs and then link it back to a query which is same as the first but only where the customer occurs once, unfortunately I get an error telling me that the query is not updateable.
I've attempted to create a subquery [in SQL] to remedy the problem but I've not come accross the EXISTS word before, when the query runs it does not appear to do what I'd like, this is the SQL that I've created inorder to display only customers from my 'cancellations list' who occur only once on the 'orders' table:-
SELECT [Canc list].[ACCOUNT NUMBER]
FROM [canc list]
WHERE Exists
(SELECT ([canc list].[ACCOUNT NUMBER]), Count([canc list].[ACCOUNT NUMBER])
FROM [Orders] RIGHT JOIN [canc list] ON [orders].[Account Number] = [canc list].[ACCOUNT NUMBER]
WHERE ([orders].[Not Converted/Cancelled]) In ('c','j')
GROUP BY [canc list].[ACCOUNT NUMBER]
HAVING count ([canc list].[account number]) = 1)
ORDER BY [canc list].[ACCOUNT NUMBER];
I could copy counts etc into more tables but as I won't be updating the orders myself I was hoping for some kind of user friendly method for my colleagues to use.
Does anybody have any suggestions as to how to get around the problem?
Many Thanks in Advance
Ian