2016-06-27 10 views
1

Ich habe eine Frage - Wenn ich versuche, diese SELECT-Anweisung auszuführen, erhalte ich nichts. Ich möchte 0 Werte für die zwei Spalten erhalten. Als ich versuchte, mit ISNULL() oder COALESCE(), aber nichts ist happened.Here die SELECT-Anweisung ist:Die Stored Procedure gibt NULL statt 0 zurück

SELECT 
    ACI.codinv AS codinv 
    , ISNULL(COUNT(distinct ACI.appln_id), 0) AS CountInd 
From  
    i_applnid_codinv aci 
    Inner Join i_applndata d On aci.appln_id = d.appln_id 
    Inner Join 
     (Select x.appln_id, Count(x.codinv) As Count_codinv 
      From 
      i_applnid_codinv x 
      Group By x.appln_id 
      Having Count(x.codinv) = 2) ac2 On ac2.appln_id = aci.appln_id 
Where 
    aci.codinv = 2222 
Group by 
    ACI.codinv 
+0

was ist die ausgabe, die Sie erhalten.die where-Klausel irgendwelche Übereinstimmungen? – TheGameiswar

+0

Die Ausgabe erfolgt nur mit den Headern. Es gibt keine Übereinstimmungen in diesem Fall, so dass ich 0 und 0 für die zwei Spalten anzeigen möchte! Ist das möglich? –

+0

Sind Sie sicher, dass Ihre inneren Joins keine Datenunterdrückung verursachen? Wechseln Sie zu linken Joins, um zu sehen, ob Sie Ergebnisse sehen. –

Antwort

0

Cant wie unten mit aus Modifizieren Ihrer query..Try getan werden ..

Pseudo Code:

select * from orderstest where empid=200 --this doesnt result any values 

if @@rowcount=0 
select orderid,custid from orderstest where empid=200 
union all 
select top 1 null,null from orderstest 

Ausgang:

orderid custid 
null  null 
+0

Vielen Dank für Ihren Beitrag! –

0

Sie haben keine Ergebnisse. Überprüfen Sie etwas wie das ...

IF (SELECT COUNT(*) From  
      i_applnid_codinv aci 
      Inner Join i_applndata d On aci.appln_id = d.appln_id 
      Inner Join 
       (Select x.appln_id, Count(x.codinv) As Count_codinv 
        From 
        i_applnid_codinv x 
        Group By x.appln_id 
        Having Count(x.codinv) = 2) ac2 On ac2.appln_id = aci.appln_id 
     Where 
      aci.codinv = 2222 
     Group by 
      ACI.codinv) > 0 
    BEGIN 
     SELECT 
       ACI.codinv AS codinv 
       , ISNULL(COUNT(distinct ACI.appln_id), 0) AS CountInd 
      From  
       i_applnid_codinv aci 
       Inner Join i_applndata d On aci.appln_id = d.appln_id 
       Inner Join 
        (Select x.appln_id, Count(x.codinv) As Count_codinv 
         From 
         i_applnid_codinv x 
         Group By x.appln_id 
         Having Count(x.codinv) = 2) ac2 On ac2.appln_id = aci.appln_id 
      Where 
       aci.codinv = 2222 
      Group by 
       ACI.codinv 
    END 
    ELSE SELECT 0,0 
+0

Vielen Dank für Ihren Beitrag! –