c#中的列名不明确,但在SQL Server中不会
本文关键字:SQL Server 但在 不明确 | 更新日期: 2023-09-27 18:01:32
我试图通过c#执行SQL命令,但告诉我,我有一个模棱两可的列名。当我复制查询到SQL Server和执行它,它的工作很好。但是通过c#,它告诉我
列名'SPCode'不明确
这是我的SQL字符串在c#:
string yourSQLstring =
"INSERT INTO totalTable (Catalogue, totalTable.SPCode, ProjNo, Quantity, Spare) " +
"SELECT Catalogue, BOMtable.SPCode, ProjNo, SUM(Quantity) AS Quantity, (SELECT CEILING(CAST (.1 * SUM(Quantity) AS FLOAT))) AS Spare FROM MainSuperTable4 " +
"FULL OUTER JOIN BOMtable ON PartNo = Catalogue " +
"WHERE ProjNo= '" + SavingData.instance.projNumber + "' AND SPCode IS NOT NULL " +
"GROUP BY Catalogue, ProjNo, SPCode";
这段代码被复制到SQL Server中,并被编辑以删除c#的内容:
INSERT INTO totalTable (Catalogue, SPCode, ProjNo, Quantity, Spare)
SELECT
Catalogue, SPCode, ProjNo,
SUM(Quantity) AS Quantity,
(SELECT CEILING(CAST (.1 * SUM(Quantity) AS FLOAT))) AS Spare
FROM MainSuperTable4
FULL OUTER JOIN BOMtable ON PartNo = Catalogue
WHERE
ProjNo = 'P140134' AND SPCode IS NOT NULL
GROUP BY
Catalogue, ProjNo, SPCode
不知道为什么它会在SQL Server中工作,而不是在c#中?
谢谢你的帮助!
将组by更改为:
"GROUP BY Catalogue, ProjNo, BOMtable.SPCode";
将insert改为:
"INSERT INTO totalTable (Catalogue, SPCode, ProjNo, Quantity, Spare) " +