需要架构建议
这就是我想要实现的目标。
我有一个包含 16 个表的 SQL Server 数据库。
现在我需要生成一个平面文件,如下所示。
Field1, value1,value2, ..., valueN
Field2, value1,value2, ..., valueN
Field3, value1,value2, ..., valueN
.
.
.
FieldN, value1,value2, ..., valueN
其中字段与多个表中的列名称相似。然而它的名字并不相同。字段名称和列名称之间存在 1 对 1 的关系。
我该怎么做?
谢谢
导入为 XML 然后执行 XSLT 怎么样?
Here's what I am trying to achieve.
I have a SQL server database with 16 tables.
Now I need to generate a flat file as following.
Field1, value1,value2, ..., valueN
Field2, value1,value2, ..., valueN
Field3, value1,value2, ..., valueN
.
.
.
FieldN, value1,value2, ..., valueN
Where Fields are similar to Column names in multiple tables. However its not the same name. There is a 1 to 1 relation between Field and column names.
How should I do this?
Thank You
How about importing as XML and then doing and XSLT?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
这可以通过几个步骤来实现:
整个事情就像你的问题一样通用。如果您提出具体问题,那么也许我们可以给您具体答案。
This can be achieved in few steps:
The whole thing is as generic as your question. If you asked specific question, then maybe we can give you specific answer.
这里非常笼统,但您可以将表输出结果集加载到二维数组中,然后按列优先顺序遍历该数组以输出文件。
您还可以创建一个数组,将列位置或名称映射到字段名称。
伪代码:
Being very general here, but you could load the table output resultset into a 2d array and then traverse the array in column-major order to output the file.
You could also create an array that maps the columns positions or names to field names.
pseudocode:
使用
PIVOT
。我写了一篇关于使用 PIVOT 的博客文章。您不需要进行与我所做的相同类型的聚合,但这应该可以帮助您入门。
Use
PIVOT
.I wrote a blog post about using PIVOT. You won't need to do the same kind of aggregation that I was doing, but this should get you started.
为了获得您想要的字段名称,您可能需要一个中间映射表,您可以手动填写该表:
To get your field names as you wish, you may need an intermediate mapping table, which you fill by hand: