Query: select mcdesp,mcidno,mcopsts,hascode from machine
Table:
| mcdesp | mcidno | mcopsts | hascode |
| A | A0001 | URWT | #### |
| A | A0001 | GOOD | #### |
| A | A0001 | GOOD | #### |
| B | A0002 | URWP | #### |
| B | A0002 | URWP | #### |
| C | A0003 | GOOD | #### |
| C | A0004 | URWT | #### |
Here i'm generating my hashcode using this script
hascode = HASHBYTES('MD5', CAST(mcidno AS VARBINARY(MAX))+ CAST(mcdesp AS VARBINARY(MAX))+CAST(mcopsts AS VARBINARY(MAX)))
Note: Same Color represents Hascodes are same.
2) My Query and its output:
select mcdesp,count(distinct hascode)as TotalMachine from machine group by mcdesp
| mcdesp | TotalMahine |
| A | 2 |
| B | 1 |
| C | 2 |
What is the Query for finding Good Machines from my "Tbl_Main"??
that is mcopsts='good'. based on Hascode.
I need a Result Like
| mcdesp | GOOD |
| A | 1 |
| B | 0 |
| C | 1 |
Iftikar HussainPosted Jun 24, 2013, 2:16 AM
You can do like below
select mcdesp,MAX(GoodCount) as Good from
Regards,
Iftikar
Remember to click "Mark as Answer" on the post, if it helps you.
VenkatesanPosted Jun 22, 2013, 12:50 AM
Pankaj PandeyPosted Jun 21, 2013, 9:33 AM