SQLTeam.com | Weblogs | Forums

Using returned data in new Query


#1

Hi, 1st post so hopefully you can assist me. I have a query called STCAGSENT, it returns the data I need, I now wish to pull a new data set, from a different source, and limit it so that ACCOUNT_NAME returns if it is the same as ACCOUNT_ID in the STCAGSENT report.

I tried this but its not right!

SELECT
ADMIN.ACCOUNT_NAME,
ADMIN.ACCOUNT_ID,
ADMIN.ORDER_ID,
ADMIN.DATE_RETURNED,
ADMIN.STATUS_CODE,
ADMIN.PART_CODE,
ADMIN.PRODUCT_NAME

FROM
ADMINXXXXXXXXXXXX

WHERE
ADMIN.ACCOUNT_NAME IN (STCAGSENT.ACCOUNT_ID)

Help Please..

Thanks

Mark


#2

Does it cause an error? Or just zero results?

If it returns zero results - may it be due to the where clause....

ADMIN.ACCOUNT_NAME IN (STCAGSENT.ACCOUNT_ID)

rather than

ADMIN.ACCOUNT_ID IN (STCAGSENT.ACCOUNT_ID)


#3

creates an Error, saying the STCAGSENT is not recognised.


#4

is this microsoft SQL server issue? what is STCAGSENT ? you call it a report?


#5

You're missing a join to the STCAGSENT table
try this

SELECT
ADMIN.ACCOUNT_NAME,
ADMIN.ACCOUNT_ID,
ADMIN.ORDER_ID,
ADMIN.DATE_RETURNED,
ADMIN.STATUS_CODE,
ADMIN.PART_CODE,
ADMIN.PRODUCT_NAME
FROM
ADMINXXXXXXXXXXXX
INNER JOIN STCAGSENT
ON ADMIN.ACCOUNT_ID=STCAGSENT.ACCOUNT_ID