我有一个名为s1.Split(',').Zip(s2.Split(','), (name, num) => new Info{Name = name, Num = num})
的表,有15列。根据{{1}},将使用某些列,并且不会使用某些列。例如,Person
为5将使用列EventId
,EventId
和Name
。同时,Address
10将使用列Phone
和EventId
。
我想我必须用Name
创建一个表,并以某种方式放入1或0来知道特定事件应该具有哪些列。但是,我不知道如何将所有这些结合起来并使其发挥作用。
我正在使用SQL Server。
答案 0 :(得分:0)
create table #test (EventID varchar(max), Name varchar(max), [Address] varchar(max), [Phone] varchar(max))
insert into #test
values ('1','Abc','gabanes adfga','1521623612'),
('3','adz','gabwega abae' ,'1521623612'),
('5','qqb','asdhahn ansxeh','1521623612'),
('5','qas','smystrj sthshs','1521623612'),
('2','qar','sthtr sthsht ','1521623612'),
('1','qha','msgnsn abawe ','1521623612')
; with cte as
(
select *, case when EventID = 5 then 1 else 0 end as Flag from #test
)
select Name, [Address], Phone from cte
where flag = 1
;with cte1
as ( select *, case when EventID = 5 then 1 else 0 end as Flag from #test )
select Name, Phone from cte1
where flag != 1
我已经随机命名了列,只是将垃圾数据放入字段中。但是,希望这有助于实现您的目标。