|
想象一个场景,我想[FormValues]基于as标题的[Title]列从as在数据中获取动态报告[ReportItems]。7 m% p" x; q3 W1 [: Z% A8 e0 a
我真的很困惑怎么做,尝试了很多方法,但没有一个能很好地工作。
) v8 c- G! _5 Z2 y5 I3 E7 K我应该能够给一个过程一个过程[ReportID]并得到结果。; X) ~! l3 `7 U3 I5 _, X) G/ T
[FormID]和[FieldID]两表之间的关系是关键。- \9 Y) P) H$ E9 Y5 H
感谢任何帮助。% G0 U$ D$ s5 x5 n
CREATE TABLE #ReportItems( ReportItemID [uniqueidentifier] NOT NULL primary key, ReportID [uniqueidentifier] NOT NULL, FormID [uniqueidentifier] NOT NULL, FieldID [uniqueidentifier] NOT NULL, Title nvarchar(100) NOT NULL) GOinsert into #ReportItemsselect '5674d274-b146-4251-be0d-a15000e7cefa','597d37c0-563b-42f0-99be-a15000dc7a65','01304636-fabe-4a3e-9487-a14b012f9a61','ba6b9b1a-92ef-4905-830a-a15000d05f7a','First Name'insert into #ReportItemsselect '5674d274-b146-4252-be0d-a15000e7cefa','597d37c0-563b-42f0-99be-a15000dc7a65','01304636-fabe-4a3e-9487-a14b012f9a61','ba6b9b1a-92ef-4905-830a-a15000d05f7b','Last Name'insert into #ReportItemsselect '5674d274-b146-4253-be0d-a15000e7cefa','597d37c0-563b-42f0-99be-a15000dc7a65','01304636-fabe-4a3e-9487-a14b012f9a61','ba6b9b1a-92ef-4905-830a-a15000d05f7c','Age'GOCREATE TABLE #FormValues( ValueID uniqueidentifier NOT NULL primary key, FormID uniqueidentifier NULL, FieldID uniqueidentifier NOT NULL, UserName nvarchar(100) NOT NULL, Value nvarchar(max) null)GOinsert into #FormValuesselect 'af6dc400-3972-49ff-9711-a1520002359e','01304636-fabe-4a3e-9487-a14b012f9a61','ba6b9b1a-92ef-4905-830a-a15000d05f7a','user 1','Mike'insert into #FormValuesselect 'af6dc400-3972-49ff-9721-a1520002359e','01304636-fabe-4a3e-9487-a14b012f9a61','ba6b9b1a-92ef-4905-830a-a15000d05f7b','user 1','Oscar'insert into #FormValuesselect 'af6dc400-3972-49ff-9731-a1520002359e','01304636-fabe-4a3e-9487-a14b012f9a61','ba6b9b1a-92ef-4905-830a-a15000d05f7c','user 1','20'insert into #FormValuesselect 'af6dc400-3972-49ff-9741-a1520002359e','01304636-fabe-4a3e-9487-a14b012f9a61','ba6b9b1a-92ef-4905-830a-a15000d05f7a','user 2','Merry'insert into #FormValuesselect 'af6dc400-3972-49ff-9761-a1520002359e','01304636-fabe-4a3e-9487-a14b012f9a61','ba6b9b1a-92ef-4905-830a-a15000d05f7c','user 2','23'insert into #FormValuesselect 'af6dc400-3972-49ff-9771-a1520002359e','01304636-fabe-4a3e-9487-a14b012f9a61','ba6b9b1a-92ef-4905-830a-a15000d05f7a','user 3','Alen'insert into #FormValuesselect 'af6dc400-3972-49ff-9781-a1520002359e','01304636-fabe-4a3e-9487-a14b012f9a61','ba6b9b1a-92ef-4905-830a-a15000d05f7b','user 3','Escott'insert into #FormValuesselect 'af6dc400-3972-49ff-9791-a1520002359e','01304636-fabe-4a3e-9487-a14b012f9a61','ba6b9b1a-92ef-4905-830a-a15000d05f7c','user 3','28'GOSelect * from #ReportItemsSelect * from #FormValuesGO我想要这样的报告作为结果:6 R$ d Z' m+ @2 A6 J9 w7 x0 n8 E
User Name | First Name | Last Name | AgeUser 1 | Mike | Oscar | 20User 2 | Merry | | 23User 3 | Alen | Escott | 28User n | ... | ... | ...drop table #ReportItemsdrop table #FormValues 0 y1 `1 T5 ?0 U& S3 Q7 F5 L
解决方案: |
|