SELECT
dbo.M_Cassette.ln_CassetteNo,
dbo.Prescription.DrugCd,
dbo.Prescription.DrugName,
Sum(dbo.Prescription.DispensedDose) AS DispensedDose,
dbo.Prescription.PatientId,
dbo.Prescription.PatientName,
CONVERT(VARCHAR,dbo.Prescription.PrescriptionDate,103) AS PrescriptionDate
FROM
dbo.Prescription
INNER JOIN dbo.M_Drug ON dbo.Prescription.DrugCd = dbo.M_Drug.vc_HostCd1
INNER JOIN dbo.M_Cassette ON dbo.M_Drug.vc_DrugCd = dbo.M_Cassette.vc_DrugCd
WHERE
(dbo.Prescription.PatientName = 'นางฉวี ทองบ้านไทร ')
GROUP BY
dbo.Prescription.DrugCd,
dbo.Prescription.DrugName,
dbo.M_Drug.vc_HostCd1,
dbo.M_Cassette.ln_CassetteNo,
dbo.Prescription.PatientId,
dbo.Prescription.PatientName,
dbo.Prescription.PrescriptionDate
ORDER BY
dbo.Prescription.PrescriptionDate ASC
และตอนแสดงผลที่ vb Code (VB.NET)
dt_Patient_UseDrug.Columns.Clear()
dt_Patient_UseDrug.Columns.Add("ln_CassetteNo", GetType(String))
dt_Patient_UseDrug.Columns.Add("DrugCd", GetType(String))
dt_Patient_UseDrug.Columns.Add("DrugName", GetType(String))
dt_Patient_UseDrug.Columns.Add("DispensedDose", GetType(String))
dt_Patient_UseDrug.Columns.Add("PatientName", GetType(String))
dt_Patient_UseDrug.Columns.Add("PrescriptionDate", GetType(String))
'------------------RP-------------------------
'dss.Clear()
ds.Tables().Clear()
ds = clsP.Patient_UseDrug(SchName)
If ds.Tables(0).Rows.Count = 0 Then MsgBox("ไม่มีข้อมูล") : Exit Sub
dt_Patient_UseDrug.Rows.Clear()
'Dim courow As Integer
'courow = ds.Tables(0).Rows.Count
'For i As Integer = 0 To courow - 1
For i = 0 To ds.Tables(0).Rows.Count - 1
dt_Patient_UseDrug.Rows.Add(New Object() {ds.Tables(0).Rows(i).Item("ln_CassetteNo").ToString, _
ds.Tables(0).Rows(i).Item("DrugCd").ToString, _
ds.Tables(0).Rows(i).Item("DrugName").ToString, _
ds.Tables(0).Rows(i).Item("DispensedDose").ToString, _
ds.Tables(0).Rows(i).Item("PatientName").ToString, _
ds.Tables(0).Rows(i).Item("PrescriptionDate").ToString})
Next
Tag : .NET, Ms SQL Server 2012, VS 2012 (.NET 4.x)