在SQL中将临时表解析为另一个表,保留列名
我有一个临时表,看起来像这样。
| USER_NO | MY_CODE1 | MY_CODE2 |
| UserNo1 | UserNo1_Code1 | UserNo1_Code2 |
| UserNo2 | UserNo2_Code1 | UserNo2_Code2 |
其中第一行是列名称,第二行和第三行是值。我需要将这些记录附加到另一个表中。
| CusRef | CodeName | CodeValue |
| UserNo1 | MY_CODE1 | UserNo1_Code1 |
| UserNo2 | MY_CODE2 | UserNo1_Code2 |
| UserNo2 | MY_CODE1 | UserNo2_Code1 |
| UserNo2 | MY_CODE2 | UserNo2_Code2 |
其他表中还有许多其他字段,我需要从其他表中引用这些字段,但这是另一个问题。
我可以使用什么 SQL 来使这第一部分工作?
I have a temporary table which looks something like this.
| USER_NO | MY_CODE1 | MY_CODE2 |
| UserNo1 | UserNo1_Code1 | UserNo1_Code2 |
| UserNo2 | UserNo2_Code1 | UserNo2_Code2 |
Where the first line is column names, the 2nd and 3rd are values. I need to append these records into another table.
| CusRef | CodeName | CodeValue |
| UserNo1 | MY_CODE1 | UserNo1_Code1 |
| UserNo2 | MY_CODE2 | UserNo1_Code2 |
| UserNo2 | MY_CODE1 | UserNo2_Code1 |
| UserNo2 | MY_CODE2 | UserNo2_Code2 |
There a number of other fields in that other table which I need to reference from other table but that is another issue.
What SQL could I use to make this first bit work?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
通过
UNPIVOT
可以获得您想要的结果Your desired results can be obtained with
UNPIVOT