Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/72.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql ode>仅限。用于选择该行的逻辑是什么? ID Account_Number Plan Deposits Tax1 Tax2 10 123456 PRINC10 _Sql_Sql Server_Sql Server 2008 - Fatal编程技术网

Sql ode>仅限。用于选择该行的逻辑是什么? ID Account_Number Plan Deposits Tax1 Tax2 10 123456 PRINC10

Sql ode>仅限。用于选择该行的逻辑是什么? ID Account_Number Plan Deposits Tax1 Tax2 10 123456 PRINC10 ,sql,sql-server,sql-server-2008,Sql,Sql Server,Sql Server 2008,ode>仅限。用于选择该行的逻辑是什么? ID Account_Number Plan Deposits Tax1 Tax2 10 123456 PRINC10 4;4 4256.45;1567.45 4256.45;1567.45 11 123456 KrINC11 4;4 4256.45;1567.45 4256.45;1567.4

ode>仅限。用于选择该行的逻辑是什么?
ID   Account_Number    Plan       Deposits       Tax1            Tax2

10   123456            PRINC10      4;4       4256.45;1567.45  4256.45;1567.45


11   123456            KrINC11      4;4       4256.45;1567.45  4256.45;1567.45 
 Select [ID], [account_number], [Plan], [Deposits], [Tax1], [Tax2]
 From MVTable
 Cross apply dbo.DelimitedSplit8K(MVTable.Deposits, ';') as Depositlist
 Cross apply dbo.DelimitedSplit8K(MVTable.Tax1, ';') as Tax1List
 Cross apply dbo.DelimitedSplit8K(MVTable.Tax2, ';') as Tax2List
  `enter code here`Where DepositList.Itemnumber = Tax1list.itemnumber
  and Depositlist.itemnumber = Tax2list.itemnumber
ID   account_number     Plan     Deposits   Tax1         Tax2 

10   123456             PRINC10    4        4256.45     4256.45

10   123456             PRINC10    4        1567.45     1567.45

11   123456             KrINC11    4        4256.45     4256.45

11   123456             KrINC11    4        1567.45     1567.45
ID   account_number     Plan     Deposits   Tax1         Tax2 

10   123456             PRINC10    4        4256.45     4256.45

11   123456             KrINC11    4        1567.45     1567.45
with cte as (
      select id, account_number, plan,
             convert(varchar(max), left(deposits, charindex(';', deposits + ';') - 1)) as deposit,
             convert(varchar(max), left(tax2, charindex(';', tax2 + ';') - 1)) as tax1,
             convert(varchar(max), left(tax2, charindex(';', tax2 + ';') - 1)) as tax2,
             convert(varchar(max), stuff(deposits, 1, charindex(';', deposits + ';'), '')) as deposit_rest,
             convert(varchar(max), stuff(tax1, 1, charindex(';', tax1 + ';'), '')) as tax1_rest,
             convert(varchar(max), stuff(tax2, 1, charindex(';', tax2 + ';'), '')) as tax2_rest
      from t
      union all
      select id, account_number, plan,
             convert(varchar(max), left(deposit_rest, charindex(';', deposit_rest + ';') - 1)) as deposit,
             convert(varchar(max), left(tax2_rest, charindex(';', tax2_rest + ';') - 1)) as tax1,
             convert(varchar(max), left(tax2_rest, charindex(';', tax2_rest + ';') - 1)) as tax2,
             convert(varchar(max), stuff(deposit_rest, 1, charindex(';', deposit_rest + ';'), '')) as deposit_rest,
             convert(varchar(max), stuff(tax1_rest, 1, charindex(';', tax1_rest + ';'), '')) as tax1_rest,
             convert(varchar(max), stuff(tax2_rest, 1, charindex(';', tax2_rest + ';'), '')) as tax2_rest
       from cte
       where deposit_rest <> ''
      )
select *
from cte;
select id, account_number, [plan],
convert(varchar(max), left(deposits, charindex(';', deposits) - 1)) as deposit,
convert(varchar(max), left(tax2, charindex(';', tax2) - 1)) as tax1,
convert(varchar(max), left(tax2, charindex(';', tax2) - 1)) as tax2
from ##t
id  account_number  plan    deposit tax1        tax2
10  123456          PRINC10     4   4256.45     4256.45
11  123456          KrINC11     4   4256.45     4256.45