Fetstil Fetstil Kursiv Understrykning linje färgläggning tabellverk Punktlista Nummerlista Vänster Centrerat högerställt Utfyllt Länk Bild htmlmode
  • Forum & Blog
    • Forum - översikt
      • .Net
        • asp.net generellt
        • c#
        • vb.net
        • f#
        • silverlight
        • microsoft surface
        • visual studio .net
      • databaser
        • sql-server
        • databaser
        • access
        • mysql
      • mjukvara klient
        • datorer och komponenter
        • nätverk, lan/wan
        • operativsystem
        • programvaror
        • säkerhet, inställningar
        • windows server
        • allmänt
        • crystal reports
        • exchange/outlook
        • microsoft office
      • mjukvara server
        • active directory
        • biztalk
        • exchange
        • linux
        • sharepoint
        • webbservers
        • sql server
      • appar (win/mobil)
      • programspråk
        • c++
        • delphi
        • java
        • quick basic
        • visual basic
      • scripting
        • asp 3.0
        • flash actionscript
        • html css
        • javascript
        • php
        • regular expresssion
        • xml
      • spel och grafik
        • DirectX
        • Spel och grafik
      • ledning
        • Arkitektur
        • Systemutveckling
        • krav och test
        • projektledning
        • ledningsfrågor
      • vb-sektioner
        • activeX
        • windows api
        • elektronik
        • internet
        • komponenter
        • nätverk
        • operativsystem
      • övriga forum
        • arbete karriär
        • erbjuda uppdrag och tjänster
        • juridiska frågor
        • köp och sälj
        • matematik och fysik
        • intern information
        • skrivklåda
        • webb-operatörer
    • Posta inlägg i forumet
    • Chatta med andra
  • Konto
    • Medlemssida
    • Byta lösenord
    • Bli bonsumedlem
    • iMail
  • Material
    • Tips & tricks
    • Artiklar
    • Programarkiv
  • JOBB
  • Student
    • Studentlicenser
  • KONTAKT
    • Om pellesoft
    • Grundare
    • Kontakta oss
    • Annonsering
    • Partners
    • Felanmälan
  • Logga in

Hem / Forum översikt / inlägg

Posta nytt inlägg


Summera Antal om fält är större än 0

Postades av 2007-12-05 07:41:32 - Gert Lindholm, i forum sql-server/msde, Tråden har 3 Kommentarer och lästs av 1137 personer

Har en tabell bo_MatchResult
Med 4 st fält MatchResultRound1 ... 4
Om MatchResultRound1 > 0 ... Round4 > 0 vill jag få ut summan av av dessa.

174 186 193 246 4
161 0 204 181 3
204 267 180 200 4
206 258 257 213 4
218 189 172 186 4
209 199 201 190 4
186 182 175 149 4
159 208 189 162 4
0 213 0 0 1

SELECT      
MatchResultRoundResult1, MatchResultRoundResult2, MatchResultRoundResult3, MatchResultRoundResult4,
(SELECT SUM(COUNT MatchResultRoundResult1 AND MatchResultRoundResult2 AND MatchResultRoundResult3 AND MatchResultRoundResult4) AS Ser
FROM bo_MatchResult WHERE MatchResultRound1 >0 AND MatchResultRoundResult2 >0 AND MatchResultRoundResult3 >0 AND MatchResultRoundResult4 >0)
FROM bo_MatchResult
WHERE     (bo_MatchResult.MatchResultMatchId = 2048075 AND bo_MatchResult.MatchResultHomeOrAwayTeam ='H')
ORDER BY bo_MatchResult.MatchResultHomeOrAwayTeam DESC


Svara

Sv: Summera Antal om fält är större än 0

Postades av 2007-12-05 08:10:28 - Johan Djupmarker

Såhär borde fungera:

SELECT      
MatchResultRoundResult1, MatchResultRoundResult2, MatchResultRoundResult3, MatchResultRoundResult4,
CASE
 WHEN MatchResultRoundResult1 > 0
  THEN 1
 ELSE 0
END
+
CASE
 WHEN MatchResultRoundResult2 > 0
  THEN 1
 ELSE 0
END
+
CASE
 WHEN MatchResultRoundResult3 > 0
  THEN 1
 ELSE 0
END
+
CASE
 WHEN MatchResultRoundResult4 > 0
  THEN 1
 ELSE 0
END
AS Summa

FROM bo_MatchResult
WHERE     (bo_MatchResult.MatchResultMatchId = 2048075 AND bo_MatchResult.MatchResultHomeOrAwayTeam ='H')
ORDER BY bo_MatchResult.MatchResultHomeOrAwayTeam DESC


/Johan


Svara

Sv:Summera Antal om fält är större än 0

Postades av 2007-12-05 08:37:40 - Gert Lindholm

Kanon!
Tack


Svara

Sv:Summera Antal om fält är större än 0

Postades av 2007-12-05 09:14:21 - Gert Lindholm

Försöker få in det i min nuvarande SP:
Men får error Msg 116, Level 16, State 1, Line 1
Only one expression can be specified in the select list when the subquery is not introduced with EXISTS.

SELECT  bo_Match.MatchId, bo_MatchResult.MatchResultLicNbr, bo_Club.ClubName,  
        bo_Licence.FirstName + ' ' + bo_Licence.SurName AS SpelarNamn, bo_MatchResult.MatchResultShirtNo, 
        bo_MatchResult.MatchResultRoundResult1 + bo_MatchResult.MatchResultRoundResult2 + 
        bo_MatchResult.MatchResultRoundResult3 + bo_MatchResult.MatchResultRoundResult4
        AS MatchResultPlayer,  
        bo_MatchResult.MatchResultHomeOrAwayTeam, bo_MatchResult.MatchResultPlace, 
SUM(bo_MatchResult.MatchResultRankPoint1 + bo_MatchResult.MatchResultRankPoint2 + 
bo_MatchResult.MatchResultRankPoint3 + bo_MatchResult.MatchResultRankPoint4) AS Banp,
(SELECT bo_MatchResult.MatchResultRoundResult1, bo_MatchResult.MatchResultRoundResult2, 
bo_MatchResult.MatchResultRoundResult3, bo_MatchResult.MatchResultRoundResult4,
CASE
 WHEN bo_MatchResult.MatchResultRoundResult1 > 0
  THEN 1
 ELSE 0
END
+
CASE
 WHEN bo_MatchResult.MatchResultRoundResult2 > 0
  THEN 1
 ELSE 0
END
+
CASE
 WHEN bo_MatchResult.MatchResultRoundResult3 > 0
  THEN 1
 ELSE 0
END
+
CASE
 WHEN bo_MatchResult.MatchResultRoundResult4 > 0
  THEN 1
 ELSE 0
END
FROM bo_MatchResult) AS Summa
FROM         bo_Licence INNER JOIN
                      bo_MatchResult ON bo_Licence.LicNbr = bo_MatchResult.MatchResultLicNbr INNER JOIN
                      bo_Match ON bo_MatchResult.MatchResultMatchId = bo_Match.MatchId INNER JOIN
                      bo_Hall ON bo_Match.MatchHallId = bo_Hall.HallId INNER JOIN
                      bo_Division ON bo_Match.MatchDivisionId = bo_Division.DivisionId INNER JOIN
                      bo_Club ON bo_MatchResult.MatchResultTeamId = bo_Club.ClubId
WHERE     (bo_MatchResult.MatchResultMatchId = 2048075 AND bo_MatchResult.MatchResultHomeOrAwayTeam ='H')
GROUP BY bo_Match.MatchId,bo_MatchResult.MatchResultLicNbr, bo_Club.ClubName,bo_Licence.FirstName, bo_Licence.SurName,
bo_MatchResult.MatchResultShirtNo,bo_MatchResult.MatchResultRoundResult1,
bo_MatchResult.MatchResultRoundResult2,bo_MatchResult.MatchResultRoundResult3,
bo_MatchResult.MatchResultRoundResult4,
bo_MatchResult.MatchResultHomeOrAwayTeam, bo_MatchResult.MatchResultPlace
ORDER BY bo_MatchResult.MatchResultHomeOrAwayTeam DESC, bo_MatchResult.MatchResultShirtNo


Svara

Nyligen

  • 14:24 CBD regelbundet?
  • 14:23 CBD regelbundet?
  • 14:22 Har du märkt några verkliga fördel
  • 09:09 Vill du köpa medicinska tester?
  • 12:47 Vem beviljar assistansen – kommune
  • 14:17 Någon med erfarenhet av hemstädnin
  • 14:14 Bör man använda sig av en båtförme
  • 14:12 Finns det någon intressant hundblo

Sidor

  • Hem
  • Bli bonusmedlem
  • Läs artiklar
  • Chatta med andra
  • Sök och erbjud jobb
  • Kontakta oss
  • Studentlicenser
  • Skriv en artikel

Statistik

Antal besökare:
Antal medlemmar:
Antal inlägg:
Online:
På chatten:
4 569 617
27 953
271 709
5 748
0

Kontakta oss

Frågor runt konsultation, rådgivning, uppdrag, rekrytering, annonsering och övriga ärenden. Ring: 0730-88 22 24 | pelle@pellesoft.se

© 1986-2013 PelleSoft AB. Last Build 4.1.7169.18070 (2019-08-18 10:02:21) 4.0.30319.42000
  • Om
  • Kontakta
  • Regler
  • Cookies