0

Getting error while executing following query in access 2007, how to solve this?

my query is :

SELECT
          A.PRODUCT
        , A.DISPBANK
        , COUNT(*) AS RecCount
        , SUM(Amt) AS TotAmt
FROM
          CBWCFAPENDINGPAYMENTDATA A
WHERE
          A.MATCH     ='Y'
          AND A.ID LIKE'*(SELECT [CASHIN_ID] FROM CBWCFAMISUPLOAD WHERE VENDOR='BRINKS' AND NZ(MATCH,'')='Y')*'
GROUP BY
          A.PRODUCT
        , A.DISPBANK

enter image description here

13
  • Can you give exmple of data in your tables, and explain what results you are trying to return please? Commented Apr 28, 2017 at 10:39
  • There's no space between Like and ' - LIKE'*(SELECT ..... Also - can you use a Select statement like that within a Like (asking as not sure)? Commented Apr 28, 2017 at 10:41
  • also you should be using double quotes not single Commented Apr 28, 2017 at 10:42
  • i'm trying to return distinct columns data from CBWCFAPENDINGPAYMENTDATA table where MATCH column should be 'Y' and id comes from CBWCFAMISUPLOAD table they may be single id or multiple id thats y place like there Commented Apr 28, 2017 at 10:43
  • ok in that case yes you can check for the string in your like clause, but you need to use double quotes not single in access, this will be the issue Commented Apr 28, 2017 at 10:44

2 Answers 2

1

You can't have a subquery inside the LIKE string.

You could use DLookup and string concatenation for this.

AND A.ID LIKE '*' & 
  DLookup("[CASHIN_ID]", "CBWCFAMISUPLOAD", "VENDOR='BRINKS' AND NZ(MATCH,'')='Y'" ) & '*'
Sign up to request clarification or add additional context in comments.

Comments

1

Ok so your answer should be like the below, and will calculate what you need if the tables have a one to many relationship, and returns all rows from table a where the id is found in table b:

     SELECT A.PRODUCT, A.DISPBANK,Count(*) as RecCount,Sum(Amt) as TotAmt FROM CBWCFAPENDINGPAYMENTDATA A WHERE A.MATCH="Y" AND Format(CStr([A.ID])) IN (SELECT [CASHIN_ID] FROM CBWCFAMISUPLOAD WHERE VENDOR="BRINKS" AND NZ(MATCH,"")="Y")) GROUP BY A.PRODUCT, A.DISPBANK

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.