2017-08-10 60 views
0

我有以下的訪問表和空字段:刪除空字段的記錄,並與移動值的字段再創紀錄

Analyse Analysed Finished FAR_Send RMA 
Product1 
           Product2 
      Product3 
        Product4 
        Product5 
      Product6 
        Product7 
              Product8 
              Product9 
        Product10 
              Product11 

我想這個更改爲以下:

Analyse Analysed Finished FAR_Send RMA 
Product1 Product3 Product4 Product2 Product8 
      Product6 Product5    Product9 
        Product7    Product11 
        Product10 

這可以通過標準查詢和沒有VB編程來完成嗎?

最好的問候,

Wamor

+0

首先,一個例子僅僅是一個例子。我們仍然需要知道規則。也許我們可以推斷他們,但是我們可能是錯的。如果你明確的話就不會有混亂。其次,如果你的請求是在SQL中進行,而不是VB,那麼爲什麼這個問題是用VB.NET標記的? – jmcilhinney

+1

您的示例看起來像您使用Access一樣使用電子表格。如果你的表有兩個字段 - 產品和狀態,這將會容易得多。然後這將有11個記錄,例如'Product1 | Analyse','Product2 | Far_Send'。然後你可以使用類似'TRANSFORM Count(Status)AS CountOfStatus選擇產品FROM MyTable GROUP BY Product ORDER BY Product PIVOT Status' –

回答

1

表需要一個唯一的標識符 - 一個自動編號字段可能會成爲。然後考慮:

查詢1:
SELECT ID, "Analyse" AS Category, Analyse AS Data FROM Tablename WHERE Not Analyse Is Null UNION SELECT ID, "Analysed", Analysed FROM Tablename WHERE Not Analysed Is Null UNION SELECT ID, "Finished", Finished FROM Tablename WHERE Not Finished Is Null UNION SELECT ID, "FAR_Send", FAR_Send FROM Tablename WHERE Not FAR_Send Is Null UNION SELECT ID, "RMA", RMA FROM Tablename WHERE Not RMA Is Null;

QUERY2:
TRANSFORM First(Query1.Data) AS FirstOfData SELECT DCount("*","Query1","Category='" & [Category] & "' AND ID<" & [ID])+1 AS Seq FROM Query1 GROUP BY DCount("*","Query1","Category='" & [Category] & "' AND ID<" & [ID])+1 PIVOT Query1.Category;

相關問題