Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Database & SysAdmin
  3. Database
  4. Want a query for for finding total number of non defected items.

Want a query for for finding total number of non defected items.

Scheduled Pinned Locked Moved Database
helpdatabasetutorialannouncement
4 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • V Offline
    V Offline
    VishwaKL
    wrote on last edited by
    #1

    Hi guys, I have 2 tables Table1,Table2 Table1 having products and serial number information, and Table2 having set of 32 check points to say that product having defect or not, i want to get only total number of non defected products for each month, say example i have 3 products in march month and only 2 products satisfy set of 32 check points and having non defect, so for this problem result will be Total Number of non defected product will be 2. i want this in query. I tried it but it giving each product defect count, i want only total number of non defect product here is my query

    WITH months (num) as(
    SELECT 1
    UNION ALL
    SELECT num+1
    FROM months
    WHERE num<12)SELECT m.num as Month,
    --isnull(t.count,0) as Total,
    isnull(t.resolved,0) as Totalresolved,
    t.YearValue as YearData FROM months m
    left join (SELECT month(ProgramStartedDate) as Month,YEAR(ProgramStartedDate) as YearValue,
    --count(*) as count,

    							sum(case when (ProgrammerStatus = 1 OR ReviewerStatus = 1)  THEN 1 ELSE 0 END)as resolved  
    							FROM tb\_ProgramCheckList 
    							LEFT JOIN dbo.tb\_ProgramDetails on 
    							tb\_ProgramDetails.ProgramID =tb\_ProgramCheckList.ProgramID AND tb\_ProgramDetails.Version=tb\_ProgramCheckList.VersionID
    						   WHERE ProgramStartedDate >='10/1/2012' 
    							and ProgramStartedDate <'10/01/2013' --AND month(ProgramStartedDate)=m.num  
    							GROUP BY month(ProgramStartedDate),YEAR(ProgramStartedDate)
    

    If any body help me to solve this issue will be appreciated, Thanks and regards VISHWA

    C 1 Reply Last reply
    0
    • V VishwaKL

      Hi guys, I have 2 tables Table1,Table2 Table1 having products and serial number information, and Table2 having set of 32 check points to say that product having defect or not, i want to get only total number of non defected products for each month, say example i have 3 products in march month and only 2 products satisfy set of 32 check points and having non defect, so for this problem result will be Total Number of non defected product will be 2. i want this in query. I tried it but it giving each product defect count, i want only total number of non defect product here is my query

      WITH months (num) as(
      SELECT 1
      UNION ALL
      SELECT num+1
      FROM months
      WHERE num<12)SELECT m.num as Month,
      --isnull(t.count,0) as Total,
      isnull(t.resolved,0) as Totalresolved,
      t.YearValue as YearData FROM months m
      left join (SELECT month(ProgramStartedDate) as Month,YEAR(ProgramStartedDate) as YearValue,
      --count(*) as count,

      							sum(case when (ProgrammerStatus = 1 OR ReviewerStatus = 1)  THEN 1 ELSE 0 END)as resolved  
      							FROM tb\_ProgramCheckList 
      							LEFT JOIN dbo.tb\_ProgramDetails on 
      							tb\_ProgramDetails.ProgramID =tb\_ProgramCheckList.ProgramID AND tb\_ProgramDetails.Version=tb\_ProgramCheckList.VersionID
      						   WHERE ProgramStartedDate >='10/1/2012' 
      							and ProgramStartedDate <'10/01/2013' --AND month(ProgramStartedDate)=m.num  
      							GROUP BY month(ProgramStartedDate),YEAR(ProgramStartedDate)
      

      If any body help me to solve this issue will be appreciated, Thanks and regards VISHWA

      C Offline
      C Offline
      Corporal Agarn
      wrote on last edited by
      #2

      Does table 2 have 32 bit columns or two columns with one record per check?

      V 1 Reply Last reply
      0
      • C Corporal Agarn

        Does table 2 have 32 bit columns or two columns with one record per check?

        V Offline
        V Offline
        VishwaKL
        wrote on last edited by
        #3

        each program having 32 bit checks to prove the item is defect or not

        M 1 Reply Last reply
        0
        • V VishwaKL

          each program having 32 bit checks to prove the item is defect or not

          M Offline
          M Offline
          Mycroft Holmes
          wrote on last edited by
          #4

          Great design - what happens when you want to add a new check! You need to add the values of the 32 checks (presumably booleans where 1= positive) if it = 32 then the program passes andything els the program fails.

          Select *
          From (Select C1 + C2+C3+... as checktotal, Program from table) as SubQuery
          where checktotal = 32

          Never underestimate the power of human stupidity RAH

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups