SELECT
SUM(b.iMoney) AS IMONEY,
SUM(b.iQuantity) AS IQTY
FROM
[192.168.0.4].ims_data.dbo.pd_size AS c
ON (b.cInvCode = c.pd_cod collate Thai_CI_AI)
LEFT JOIN
[192.168.0.4].ims_data.dbo.pd_unit AS d
ON(c.unit_id = d.unit_id)
ผมจะดึง unit_id ซึ่งไม่ได้ SUM AS มันไม่ออกนะครับ ออกแต่พวกที่ SUM AS แล้วนะครับ
Select c.unit_id,
SUM(b.iMoney) AS IMONEY,
SUM(b.iQuantity) AS IQTY
FROM
[192.168.0.4].ims_data.dbo.pd_size AS c
ON (b.cInvCode = c.pd_cod collate Thai_CI_AI)
LEFT JOIN
[192.168.0.4].ims_data.dbo.pd_unit AS d
ON(c.unit_id = d.unit_id)
$strSQL = "SELECT
SUM(b.iMoney) AS IMONEY,
SUM(b.iQuantity) AS IQTY
FROM [192.168.0.20].UFDATA_009_2012.dbo.SaleBillVouch AS a
RIGHT OUTER JOIN
[192.168.0.20].UFDATA_009_2012.dbo.SaleBillVouchs AS b
ON (a.SBVID = b.SBVID)
LEFT JOIN
[192.168.0.4].ims_data.dbo.pd_size AS c
ON (b.cInvCode = c.pd_cod collate Thai_CI_AI)
LEFT JOIN
[192.168.0.4].ims_data.dbo.pd_unit AS d
ON(c.unit_id = d.unit_id)
WHERE (a.dDate BETWEEN '$startdatebill' AND '$enddatebill')
AND b.cInvCode = '$id'";
$strSQL = "SELECT
SUM(b.iMoney) AS IMONEY,
SUM(b.iQuantity) AS IQTY
FROM [192.168.0.20].UFDATA_009_2012.dbo.SaleBillVouch AS a
RIGHT OUTER JOIN
[192.168.0.20].UFDATA_009_2012.dbo.SaleBillVouchs AS b
ON (a.SBVID = b.SBVID)
LEFT JOIN
[192.168.0.4].ims_data.dbo.pd_size AS c
ON (b.cInvCode = c.pd_cod collate Thai_CI_AI)
LEFT JOIN
[192.168.0.4].ims_data.dbo.pd_unit AS d
ON(c.unit_id = d.unit_id)
WHERE (a.dDate BETWEEN '$startdatebill' AND '$enddatebill')
AND b.cInvCode = '$id'";
แบบนี้ใช้งานได้ใช่มั๊ยครับ
แต่พอใส่
Code (PHP)
$strSQL = "SELECT d.unit_id,
SUM(b.iMoney) AS IMONEY,
SUM(b.iQuantity) AS IQTY
FROM [192.168.0.20].UFDATA_009_2012.dbo.SaleBillVouch AS a
RIGHT OUTER JOIN
[192.168.0.20].UFDATA_009_2012.dbo.SaleBillVouchs AS b
ON (a.SBVID = b.SBVID)
LEFT JOIN
[192.168.0.4].ims_data.dbo.pd_size AS c
ON (b.cInvCode = c.pd_cod collate Thai_CI_AI)
LEFT JOIN
[192.168.0.4].ims_data.dbo.pd_unit AS d
ON(c.unit_id = d.unit_id)
WHERE (a.dDate BETWEEN '$startdatebill' AND '$enddatebill')
AND b.cInvCode = '$id'";
Warning: mssql_query() [function.mssql-query]: message: Column '192.168.0.4.ims_data.dbo.pd_unit.unit_nam' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause. (severity 16) in
$strSQL = "SELECT *,
SUM(b.iMoney) AS IMONEY,
SUM(b.iQuantity) AS IQTY
FROM [192.168.0.20].UFDATA_009_2012.dbo.SaleBillVouch AS a
RIGHT OUTER JOIN
[192.168.0.20].UFDATA_009_2012.dbo.SaleBillVouchs AS b
ON (a.SBVID = b.SBVID)
LEFT JOIN
[192.168.0.4].ims_data.dbo.pd_size AS c
ON (b.cInvCode = c.pd_cod collate Thai_CI_AI)
LEFT JOIN
[192.168.0.4].ims_data.dbo.pd_unit AS d
ON(c.unit_id = d.unit_id)
WHERE (a.dDate BETWEEN '$startdatebill' AND '$enddatebill')
AND b.cInvCode = '$id'";
Warning: mssql_query() [function.mssql-query]: message: Column '192.168.0.20.UFDATA_009_2012.dbo.SaleBillVouch.SBVID' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause. (severity 16) in
ครับ
Code (PHP)
$strSQL = "SELECT *,
SUM(b.iMoney) AS IMONEY,
SUM(b.iQuantity) AS IQTY
FROM [192.168.0.20].UFDATA_009_2012.dbo.SaleBillVouch AS a
RIGHT OUTER JOIN
[192.168.0.20].UFDATA_009_2012.dbo.SaleBillVouchs AS b
ON (a.SBVID = b.SBVID)
LEFT JOIN
[192.168.0.4].ims_data.dbo.pd_size AS c
ON (b.cInvCode = c.pd_cod collate Thai_CI_AI)
LEFT JOIN
[192.168.0.4].ims_data.dbo.pd_unit AS d
ON(c.unit_id = d.unit_id)
WHERE (a.dDate BETWEEN '$startdatebill' AND '$enddatebill')
AND b.cInvCode = '$id'";
ใส่ * ERROR ทันทีครับ....
Code (PHP)
$strSQL = "SELECT
SUM(b.iMoney) AS IMONEY,
SUM(b.iQuantity) AS IQTY
FROM [192.168.0.20].UFDATA_009_2012.dbo.SaleBillVouch AS a
RIGHT OUTER JOIN
[192.168.0.20].UFDATA_009_2012.dbo.SaleBillVouchs AS b
ON (a.SBVID = b.SBVID)
LEFT JOIN
[192.168.0.4].ims_data.dbo.pd_size AS c
ON (b.cInvCode = c.pd_cod collate Thai_CI_AI)
LEFT JOIN
[192.168.0.4].ims_data.dbo.pd_unit AS d
ON(c.unit_id = d.unit_id)
WHERE (a.dDate BETWEEN '$startdatebill' AND '$enddatebill')
AND b.cInvCode = '$id'";
แต่ถ้าอย่างนี้ละก็.......ผ่านครับ แต่ปัญหา..คือมันไม่ได้ Select AS นะครับผมจึงเรียกข้อมูลออกมาไม่ได้ครับ
"SELECT
MONTH(a.dDate) AS IMON,
YEAR(a.dDate) AS IYEAR,
SUM(b.iMoney) AS IMONEY,
SUM(b.iQuantity) AS IQTY
FROM [192.168.0.20].UFDATA_009_2012.dbo.SaleBillVouch AS a
RIGHT OUTER JOIN
[192.168.0.20].UFDATA_009_2012.dbo.SaleBillVouchs AS b
ON (a.SBVID = b.SBVID)
WHERE (a.dDate BETWEEN '$startdatebill' AND '$enddatebill')
AND b.cInvCode = '$id'
GROUP BY MONTH (a.dDate), YEAR (a.dDate)
";
2.อันนี้พอใส่ OR BETWEEN ก็ ERROR เลยนะครับ Incorrect syntax near '='. (severity 15) in
Code (PHP)
"SELECT
MONTH(a.dDate) AS IMON,
YEAR(a.dDate) AS IYEAR,
SUM(b.iMoney) AS IMONEY,
SUM(b.iQuantity) AS IQTY
FROM [192.168.0.20].UFDATA_009_2012.dbo.SaleBillVouch AS a
RIGHT OUTER JOIN
[192.168.0.20].UFDATA_009_2012.dbo.SaleBillVouchs AS b
ON (a.SBVID = b.SBVID)
WHERE (a.dDate BETWEEN '$startdatebill' AND '$enddatebill') OR (a.dDate BETWEEN '$summonth')
AND b.cInvCode = '$id'
GROUP BY MONTH (a.dDate), YEAR (a.dDate)
";