TSQL-SQL 2000
我正为这个问题苦苦挣扎。我有一个表 A,如下所示:
Employee_ID Dependant_FirstName DOB 1 John 12/12/1980 1 Lisa 11/11/1982 2 Mark 06/06/1985 2 Shane 07/07/1982 2 Mike 03/04/1990 3 NULL NULL
并想像这样复制表 B 中的这些数据(知道表 A 中最多只能有 6 个家属):
Employee_ID Dependant1_FirstName DOB Dependant2_FirstName DOB Dependant3_FirstName DOB 1 John 12/12/1980 Lisa 11/11/1982 NULL NULL 2 Mark 06/06/1985 Shane 07/07/1982 Mike 03/04/1990 3 NULL NULL NULL NULL NULL NULL
非常感谢您的帮助。
马克
I'm struggling with this one. I have a table A which looks like this:
Employee_ID Dependant_FirstName DOB 1 John 12/12/1980 1 Lisa 11/11/1982 2 Mark 06/06/1985 2 Shane 07/07/1982 2 Mike 03/04/1990 3 NULL NULL
and would like to copy these data in Table B like this (knowing that there could only be a maximum of 6 dependants in Table A):
Employee_ID Dependant1_FirstName DOB Dependant2_FirstName DOB Dependant3_FirstName DOB 1 John 12/12/1980 Lisa 11/11/1982 NULL NULL 2 Mark 06/06/1985 Shane 07/07/1982 Mike 03/04/1990 3 NULL NULL NULL NULL NULL NULL
Thanks very much for the help.
Marc
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
看看这个例子:
http://ryanfarley.com/blog/ archive/2005/02/17/1712.aspx
这里他将父键的子元素连接到一个字符串中,这应该允许您写出一个平面记录。
Have a look at this example:
http://ryanfarley.com/blog/archive/2005/02/17/1712.aspx
here he is concatentating the child elements of a parent key into a string which should allow you to write out a flat record.
这是一个仅适用于您的示例数据的工作示例,旨在让您了解我将如何做到这一点。我正在使用基于出生日期和姓名的伪造家属计数器。请记住,如果员工有同名的双胞胎,它就会崩溃,但如果他们这样做,那么他们就应该承受他们所拥有的终生数据混乱:)
另外,请考虑升级该 SQL Server。或者将这种转向转移到您的报告工具而不是数据库。
This is a working example for just your example data, to give an idea of how I'd do it. I'm using a faked-up dependant counter based on date of birth and name. Bear in mind it will break if an employee has twins with the same name, but if they do that, then they deserve all the lifelong data-confusion that they've got in store :)
Also, please consider upgrading that SQL Server. Or moving this kind of pivoting to your reporting tool rather than the database.
您可以
注意:我在示例中省略了 DOB 列
声明
You could
Note: I have ommitted the DOB column in the examples
Statement
请检查此代码,它可能对您有用。
Check this code please, It might work for you.