根据多个ID值访问行数据到列

时间:2015-12-10 19:50:19

标签: sql ms-access ms-access-2010 ms-access-2013

我试图将我的数据看作:

|SalesID|ItemSequence|ItemCodes|ItemType|
|  123  |    000001  |  Sheet  | Main   |
|  123  |    000002  | Blue Dye| Add on |
|  123  |    000003  |Cut Sheet| Add on |
|  123  |    000004  |  Sheet  | Main   |
|  123  |    000005  |Cut Sheet| Add on |

看起来像

|SalesID|ItemSequence|ItemCodes| Addon1  | Addon2  |
|  123  |    000001  |  Sheet  |Blue Dye |Cut Sheet|
|  123  |    000002  |  Sheet  |Cut Sheet|         |

我目前正在尝试使用效果不佳的IIf语句。

IIf([ItemSequence] = "000001" and [ItemType] = "Main", IIf([ItemSequence] =   
"000002" and [ItemType] = "Add on", [ItemCodes] = [Addon1] and
IIf([ItemSequence] = "000003" and [ItemType] = "Main",[Addon2] = "",
[Addon2] = [ItemCodes]......

这个已经非常长的IIf语句必须继续,具体取决于SalesID列出了多少项。我正在寻找一种正确的方法来做到这一点,不涉及一个50,000字的IIf语句,可能在完成时不起作用。

0 个答案:

没有答案