Venkatesan

Venkatesan

  • NA
  • 16
  • 6.9k

Plz Solve this sql Query..

Jun 21 2013 8:46 AM
1) My Table:
Query: select mcdesp,mcidno,mcopsts,hascode from machine
Table: 
mcdesp
mcidnomcopstshascode
A A0001 URWT  ####
A A0001 GOOD####
 A0001GOOD ####
B A0002URWP####
B A0002URWP####
CA0003GOOD####
CA0004URWT####

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

mcdespTotalMahine
A2
B1
C2
 Let This Tableas "Tbl_Main"

What is the Query for finding Good Machines from my "Tbl_Main"??

that is mcopsts='good'.  based on Hascode.

I need a Result Like
mcdespGOOD
A1
B0
C1




Answers (3)