troubleshooting Question

Need some help with a view

Avatar of Thomas Stockbruegger
Thomas StockbrueggerFlag for Germany asked on
Microsoft SQL ServerSQL
1 Comment1 Solution20 ViewsLast Modified:
Hallo,
I would like to change my view.
The Sum  GEWICHT_OFFEN and the Sum STCK_OFFEN I need to adjust.
So if there is no data  in View_Berechnung_bei_Fertigstellung_Warenbegleitscheine_noch_offen3 (B)
that means I have no value/data in B.[Gewicht_Warenbegleitschein_kpl and B.[Stck_Warenbegleitschein_kpl
then  the Sum must be : GEWICHT_OFFEN = A.[Gewicht_Lieferschein_kpl]
                                            STCK_OFFEN          = A.[Stck_Lieferschein_kpl]



sql.Format("create view View_Berechnung_bei_Fertigstellung_Warenbegleitscheine_und_Lieferscheine_noch_offen_4 as select\
               A.[Gewicht_Lieferschein_kpl], \
                   A.[Stck_Lieferschein_kpl],\
               B.[Gewicht_Warenbegleitschein_kpl],\
                   B.[Stck_Warenbegleitschein_kpl], \
                   A.[ABNr],\
               SUM(A.[Gewicht_Lieferschein_kpl]-B.[Gewicht_Warenbegleitschein_kpl])AS GEWICHT_OFFEN,\
               SUM(A.[Stck_Lieferschein_kpl]-B.[Stck_Warenbegleitschein_kpl])AS STCK_OFFEN\

                   FROM View_Berechnung_bei_Fertigstellung_Lieferscheine_noch_offen_2 AS A\
               inner join View_Berechnung_bei_Fertigstellung_Warenbegleitscheine_noch_offen3 AS B\
               ON A.[ABNr] = B.[ABNr]\
               group by A.[ABNr], \
                   A.[Gewicht_Lieferschein_kpl],\
                   A.[Stck_Lieferschein_kpl],\
               B.[Gewicht_Warenbegleitschein_kpl], \
                   B.[Stck_Warenbegleitschein_kpl]\
               HAVING SUM(A.[Stck_Lieferschein_kpl]-B.[Stck_Warenbegleitschein_kpl])>0");

Thank you for your help.
Best regards,
Thomas
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 1 Comment.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 1 Comment.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros