I’m getting pretty frustrated. Yes im a newbie, 2 weeks old in C# and sql server. Please go easy on me. This command is supposedly to print out InvDate, InvoiceNo, TaxAmount and SubTotal as Amount. its also supposed to drag Patientdetails from another table called PatientsDetails. The key in both is MedicalRecordID.
SqlCommand objCmd =
new SqlCommand("SELECT CONVERT(char(80), inv.[InvDate],3)
AS InvDate,inv.[InvoiceNo],inv.[TaxAmount] + inv.[SubTotal]
AS Amount,
'' AS Payment
FROM [Invoice] inv
LEFT JOIN [PatientDetails] tab
ON inv.[MedicalRecordID] = tab.[MedicalRecordID]
WHERE (inv.[InvDate] >= CONVERT(datetime, '" +
dtpFrom.Text + "', 105 ))
AND (inv.[InvDate] <= CONVERT(datetime, '" +
dtpTo.Text + "', 105))",
objConn);
This next set of commands are to print out as i want it to be.
for (int i = 0; i < 4; i++)
{
if (!objReader.IsDBNull(i))
{
string s;
s = objReader.GetDataTypeName(i);
//MessageBox.Show(s);
if (objReader.GetDataTypeName(i) == "char")
{
sw.Write(objReader.GetString(i));
}
else if (objReader.GetDataTypeName(i) == "money")
{
sw.Write(objReader.GetSqlMoney(i).ToString());
}
else if (objReader.GetDataTypeName(i) == "nvarchar")
{
sw.Write(objReader.GetString(i));
}
}
if (i < 3)
{
sw.Write("\t");
}
}
count = count + 1;
sw.WriteLine();
This is my SQL query which i guess is apparently wrong, because im not adding a SubTotal, but this is actually what i want. The InvoiceNo, InvDate, SubTotal tagged to the user.
SELECT Invoice.InvDate,
Invoice.InvoiceNo,
Invoice.TaxAmount + Invoice.SubTotal,
PatientDetails.GivenName
FROM Invoice
INNER JOIN PatientDetails
ON (Invoice.MedicalRecordID = PatientDetails.MedicalRecordID)
Try the following to write out the result
If you’re still missing fields, I would write your query as follows
You can also use
WHERE inv.[InvDate] >= @From AND inv.[InvDate] <= @Toinstead ofBETWEEN