– Codes and Baq (ver 10.1.500.45)
– Must Change CustID that you really have before testing.
– Enjoy~
With [CTE] AS
(select
(1) as [Calculated_n]
from Erp.Customer as Customer
where (Customer.CustID = 'C00015')
UNION ALL
select
(CTE.Calculated_n + 1) as [Calculated_nn]
from CTE as CTE
where (CTE.Calculated_n + 1) < 100)
,[CTE2] AS
(select
(1) as [Calculated_n]
from Erp.Customer as Customer1
where (Customer1.CustID = 'C00015')
UNION ALL
select
(CTE2.Calculated_n + 1) as [Calculated_nn]
from CTE2 as CTE2
where (CTE2.Calculated_n + 1) < 100)
select
[CROSS].[ResourceTimeUsed_JobNum] as [ResourceTimeUsed_JobNum],
[CROSS].[ResourceTimeUsed_AssemblySeq] as [ResourceTimeUsed_AssemblySeq],
[CROSS].[ResourceTimeUsed_OprSeq] as [ResourceTimeUsed_OprSeq],
[CROSS].[ResourceTimeUsed_ResourceGrpID] as [ResourceTimeUsed_ResourceGrpID],
[CROSS].[ResourceTimeUsed_ResourceID] as [ResourceTimeUsed_ResourceID],
[CROSS].[ResourceTimeUsed_StartDate] as [ResourceTimeUsed_StartDate],
[CROSS].[ResourceTimeUsed_EndDate] as [ResourceTimeUsed_EndDate],
[CROSS].[Calculated_LoadDay] as [Calculated_LoadDay],
[CROSS2].[Calculated_LoadHour] as [Calculated_LoadHour],
[CROSS].[ResourceTimeUsed_LoadDays] as [ResourceTimeUsed_LoadDays],
[CROSS2].[ResourceTimeUsed1_LoadHours] as [ResourceTimeUsed1_LoadHours],
[CROSS].[Calculated_index_id] as [Calculated_index_id]
from (select
[ResourceTimeUsed].[JobNum] as [ResourceTimeUsed_JobNum],
[ResourceTimeUsed].[AssemblySeq] as [ResourceTimeUsed_AssemblySeq],
[ResourceTimeUsed].[OprSeq] as [ResourceTimeUsed_OprSeq],
[ResourceTimeUsed].[ResourceGrpID] as [ResourceTimeUsed_ResourceGrpID],
[ResourceTimeUsed].[ResourceID] as [ResourceTimeUsed_ResourceID],
[ResourceTimeUsed].[StartDate] as [ResourceTimeUsed_StartDate],
[ResourceTimeUsed].[EndDate] as [ResourceTimeUsed_EndDate],
(SUBSTRING(cast(ResourceTimeUsed.LoadDays as nvarchar(max)), CTE_TOP.Calculated_n, CHARINDEX('~', cast(ResourceTimeUsed.LoadDays as nvarchar(max)) + '~', CTE_TOP.Calculated_n) - CTE_TOP.Calculated_n)) as [Calculated_LoadDay],
(CTE_TOP.Calculated_n + 1 - LEN(REPLACE(LEFT(cast(ResourceTimeUsed.LoadDays as nvarchar(max)), CTE_TOP.Calculated_n), '~', '' ))) as [Calculated_index_id],
(row_number() over(order by ResourceTimeUsed.JobNum, ResourceTimeUsed.AssemblySeq, ResourceTimeUsed.OprSeq)) as [Calculated_rownum],
(SUBSTRING('~' + cast(ResourceTimeUsed.LoadDays as nvarchar(max)), CTE_TOP.Calculated_n, 1)) as [Calculated_where_1],
(LEN(cast(ResourceTimeUsed.LoadDays as nvarchar(max))) + 1) as [Calculated_where_2],
(cast(ResourceTimeUsed.LoadDays as nvarchar(max))) as [Calculated_where_3],
(cast(ResourceTimeUsed.LoadHours as nvarchar(max))) as [Calculated_where_4],
[ResourceTimeUsed].[LoadDays] as [ResourceTimeUsed_LoadDays]
from (select
[CTE1].[Calculated_n] as [Calculated_n]
from CTE as CTE1) as CTE_TOP
cross join Erp.ResourceTimeUsed as ResourceTimeUsed
where ResourceTimeUsed.WhatIf = 0 and (SUBSTRING('~' + cast(ResourceTimeUsed.LoadDays as nvarchar(max)), CTE_TOP.Calculated_n, 1)) = ~ and (LEN(cast(ResourceTimeUsed.LoadDays as nvarchar(max))) + 1) > CTE_TOP.Calculated_n and (cast(ResourceTimeUsed.LoadDays as nvarchar(max))) <> and (cast(ResourceTimeUsed.LoadHours as nvarchar(max))) <>) as CROSS
inner join (select
[ResourceTimeUsed1].[JobNum] as [ResourceTimeUsed1_JobNum],
[ResourceTimeUsed1].[AssemblySeq] as [ResourceTimeUsed1_AssemblySeq],
[ResourceTimeUsed1].[OprSeq] as [ResourceTimeUsed1_OprSeq],
[ResourceTimeUsed1].[ResourceGrpID] as [ResourceTimeUsed1_ResourceGrpID],
[ResourceTimeUsed1].[ResourceID] as [ResourceTimeUsed1_ResourceID],
[ResourceTimeUsed1].[StartDate] as [ResourceTimeUsed1_StartDate],
[ResourceTimeUsed1].[EndDate] as [ResourceTimeUsed1_EndDate],
[ResourceTimeUsed1].[LoadHour] as [ResourceTimeUsed1_LoadHour],
(SUBSTRING(cast(ResourceTimeUsed1.LoadHours as nvarchar(max)), CTE_TOP2.Calculated_n, CHARINDEX('~', cast(ResourceTimeUsed1.LoadHours as nvarchar(max)) + '~', CTE_TOP2.Calculated_n) - CTE_TOP2.Calculated_n)) as [Calculated_LoadHour],
(CTE_TOP2.Calculated_n + 1 - LEN(REPLACE(LEFT(cast(ResourceTimeUsed1.LoadHours as nvarchar(max)), CTE_TOP2.Calculated_n), '~', '' ))) as [Calculated_index_id],
(row_number() over(order by ResourceTimeUsed1.JobNum, ResourceTimeUsed1.AssemblySeq, ResourceTimeUsed1.OprSeq)) as [Calculated_rownum],
(SUBSTRING('~' + cast(ResourceTimeUsed1.LoadHours as nvarchar(max)), CTE_TOP2.Calculated_n, 1)) as [Calculated_where_1],
(LEN(cast(ResourceTimeUsed1.LoadHours as nvarchar(max))) + 1) as [Calculated_where_2],
(cast(ResourceTimeUsed1.LoadHours as nvarchar(max))) as [Calculated_where_3],
(cast(ResourceTimeUsed1.LoadDays as nvarchar(max))) as [Calculated_where_4],
[ResourceTimeUsed1].[LoadHours] as [ResourceTimeUsed1_LoadHours]
from (select
[CTE21].[Calculated_n] as [Calculated_n]
from CTE2 as CTE21) as CTE_TOP2
cross join Erp.ResourceTimeUsed as ResourceTimeUsed1
where ResourceTimeUsed1.WhatIf = 0 and (SUBSTRING('~' + cast(ResourceTimeUsed1.LoadHours as nvarchar(max)), CTE_TOP2.Calculated_n, 1)) = ~ and (LEN(cast(ResourceTimeUsed1.LoadHours as nvarchar(max))) + 1) > CTE_TOP2.Calculated_n and (cast(ResourceTimeUsed1.LoadHours as nvarchar(max))) <> and (cast(ResourceTimeUsed1.LoadDays as nvarchar(max))) <>) as CROSS2 on
CROSS.ResourceTimeUsed_JobNum = CROSS2.ResourceTimeUsed1_JobNum
And
CROSS.ResourceTimeUsed_AssemblySeq = CROSS2.ResourceTimeUsed1_AssemblySeq
And
CROSS.ResourceTimeUsed_OprSeq = CROSS2.ResourceTimeUsed1_OprSeq
And
CROSS.ResourceTimeUsed_ResourceGrpID = CROSS2.ResourceTimeUsed1_ResourceGrpID
And
CROSS.ResourceTimeUsed_ResourceID = CROSS2.ResourceTimeUsed1_ResourceID
And
CROSS.ResourceTimeUsed_StartDate = CROSS2.ResourceTimeUsed1_StartDate
And
CROSS.ResourceTimeUsed_EndDate = CROSS2.ResourceTimeUsed1_EndDate
And
CROSS.Calculated_index_id = CROSS2.Calculated_index_id
order by CROSS.ResourceTimeUsed_JobNum , CROSS.ResourceTimeUsed_AssemblySeq , CROSS.ResourceTimeUsed_OprSeq , CROSS.ResourceTimeUsed_ResourceGrpID , CROSS.ResourceTimeUsed_ResourceID , CROSS.ResourceTimeUsed_StartDate , CROSS.ResourceTimeUsed_EndDate , CROSS.Calculated_LoadDay , CROSS.Calculated_index_id
yh_cte.baq (76.9 KB)