Skip to content

Instantly share code, notes, and snippets.

@AlBannaTechno
Created September 13, 2021 13:12
Show Gist options
  • Save AlBannaTechno/360322e358f6bb0db22ca4b56311c17b to your computer and use it in GitHub Desktop.
Save AlBannaTechno/360322e358f6bb0db22ca4b56311c17b to your computer and use it in GitHub Desktop.
eXtra_CustomerStatus_seed
insert into CustomerStatus (CustomerId, CreationDate, CompletedRequestsCount, OperationSystemType, DeviceId, Registered,
ModifiedDate)
select distinct cus.Id as CustomerId,
cus.CreationDate as CreationDate,
(
select Count(prs1.Id)
from ServiceRequests as prs1
where prs1.CustomerId = cus.Id AND prs1.Status = 2
)
as CompletedRequestsCount,
-- If not registered in the db for any reason we will assume it is android
ISNULL(logs.OSTypeId, 1) as OperationSystemType,
logs.MobileSerialNumber as DeviceId,
1,
NULL
from Customers as cus
left outer join Logs as logs on logs.CustomerId = cus.Id;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment