table as the main driver and LEFT OUTER JOIN to
- that way you will always get a row returned (assuming User T89387 exists). Then the only issue is to deal with the number of Initial Packages being returned as
- you can use
for that as in Solution 1 - in this case I prefer
(It is marginally faster in this instance)
For example (note, untested as we don't know your schema)
select U.Name,U.DefaultSalesOrg,LU.userlu ,
count(ISNULL(CPI.Id,0)) as [Initial Package Count]
from UsrMain U
left OUTER join csslogicalunit LU on LU.pkey = U.csslogicalunitpkey
left OUTER join CssRplOutboundPackageInfo CPI On U.Pkey=CPI.UsrMainPKey AND CPI.WorkState='Initial'
WHERE U.id= 'T89387'
group by U.Name,U.DefaultSalesOrg,LU.userlu