I suspect that you just want:
SELECT CASE co.grdtxtCertificationOther
WHEN 'อย.' THEN 2
WHEN 'มผช.' THEN 3
WHEN 'มอก.' THEN 4
WHEN 'ฮาลาล' THEN 5
WHEN 'Q' THEN 6
WHEN 'GMP' THEN 7
WHEN 'GAP' THEN 8
WHEN 'HACCP' THEN 9
WHEN 'เกษตรอินทรีย์' THEN 10 ELSE 1 END As ID
, co.[grdtxtCertificationOther] AS STDName
, co.[grdtxtCertificationNumberOther] AS STDNumber
, CONVERT(VARCHAR(24),
CASE
WHEN LEN(co.grddatIssueDateOther) >4 THEN co.grddatIssueDateOther
END,109) As SentDate
, dp.libtxtUserID As ParentID
, 1 AS Displayorder
, 0 AS isDisable
FROM Custom.tblR_docProduct dp
INNER JOIN [Custom].[tblR_docProduct_grdCertificationOther] co
ON dp.Id = co._Parent
Because at the moment, your subquery is an uncorrelated one - it introduces a new reference to the tblR_docProduct_grdCertificationOther
table, but then the WHERE
clause only makes assertions about the outer reference (with the alias co
) and the Custom.tblR_docProduct
table (with the alias dp
).
If you really did want a subquery, it's difficult to tell what it should be since the WHERE
clause inside your attempt seems to be identical to the current JOIN
condition between co
and dp
.
It's also unclear why you had an outer query that just performed a SELECT *
on a single subquery.