hi to all, i've centos 7.5 in VM. I've a problem with sql query. here i want to display product, customer and billing information by a one sql. here is a program.
void classBill::todaySales()
{
mysql = classConn::connection();
mysql->reconnect = true;
draw->clrscr();
draw->drawRect();
draw->gotoxy(15, 3);
cout << "Sales By Date";
draw->gotoxy(13,4);
cout << "-----------------";
draw->gotoxy(10, 5);
cout << "Enter Date to see sale : ( yyyy / MM/ dd ) : ";
do
{
flag = true;
draw->gotoxy(55, 5);
ioctl(STDOUT_FILENO, TIOCGWINSZ, &w);
for(int i = 55; i < w.ws_col -1; i++)
{
cout << " ";
}
draw->gotoxy(55, 5);
getline(cin,strdate);
if(strdate.empty())
{
flag == true;
}
else
{
flag = classValid::isValidDate(strdate);
if(!flag)
{
draw->gotoxy(10, 6);
cout << "invalid date please re-enter";
strdate.clear();
getc->getch();
draw->gotoxy(10, 6);
ioctl(STDOUT_FILENO, TIOCGWINSZ, &w);
mysql = classConn::connection();
// here is sql query
sql = "select p.productname, p.rate, b.quantity, b.total, b.billno, c.customername, c.contactaddress, c.mobileno, c.id as CustomerID from tableProductRecords as p, tableBilling as ";
sql += "b, tableCustomers as c where b.dateofsale = '"+ strdate+"' and p.productname in ( select productname from tableProductRecords where productid = ";
sql += "b.productid ) and c.customername in (select customername from tableCustomers where billno = b.billno) order by b.billno;";
draw->gotoxy(10, lines + 15);
cout << "Grand total : " << gtotal;
getc->getch();
}
now problem is that sql query returns unwanted rows. as in these pics. here cutomer id "2" is not included in billno = 18, customer id 2 is having bill no 2 not 18 butit customerid 2 is showing in billno with 18. how to get only rows that have correct billno and customer id.
sorry for line indentation in my pc formats is not working
one last thing howto upload images
how to get only rows that have correct billno and customer id.
But what is the correct billno and customer id?
Currently you have b.productid and b.billno. Those values are something floating around within the statement. Nothing particular. So you get a result that is more or less random.
it doesn't work. sql query returns unwanted rows, here cutomer id "2" is not included in billno = 18, customer id 2 is having bill no 2 not 18 butit customerid 2 is showing in billno with 18
what I would do is print the generated sql statement and run it in your sql tool.
fix and debug it there, and keep track of the changes so you can fix the c++. Once you have it working outside the c++, fix the c++ to generate it exactly as it was when it worked.