如何隐藏/删除此查询中的重复行
INSERT INTO uni_data_temp(sale_order_item_code,
order_date, sale_order_item_status, tracking_number, dispatch_date,
user_id) VALUES ('1000932515', cast('2015/05/16' as date), 'DISPATCHED', 'UNIPAYP1958141', '2015/05/20', '4')
答案 0 :(得分:1)
尝试使用DISTINCT
-
SELECT DISTINCT CASE
WHEN capex_billofmaterialitem.decQuantity <> '0'
THEN '0'
ELSE capex_billofmaterialitem.decQuantity
END AS decQuantity,
capex_billofmaterialitem.*
FROM capex_billofmaterialitem
JOIN capex_billofmaterial ON capex_billofmaterialitem.szbillofmaterialid = capex_billofmaterial.szbillofmaterialid
WHERE capex_billofmaterial.szprojectcode = @szProjectCode
答案 1 :(得分:0)
试试此代码
使用row_number()这是安全的方法
WITH CTE_Dup AS
(
SELECT * ROW_NUMBER()OVER (PARTITIONBY SalesOrderno, ItemNo ORDER BY SalesOrderno, ItemNo)
AS ROW_NO
from dbo.SalesOrderDetails
)
Delete FROM CTE_Dup;