Your comments
Проверил на нашей базе, все правильно посчиталось. Можно организовать к вам подключение и посмотреть, что не так?
10 years ago
скрипты повторно прогонять нет смысла, и обновлять данные тоже.
Вот теперь становится странно. А какие данные там должны быть? Получается это не чистая, только что клонированная запись?
Чтобы не было непонимания. Данные в сводке считаются по реализациям.
Чтобы не было непонимания. Данные в сводке считаются по реализациям.
ALTER procedure [dbo].[AXI_NomenklaturaRecountAnalitikaAll]
as
begin
set nocount on;
/*#Table1 - справочник номенклатуры*/
declare @Table table
(ProductID int
,DateFirstProdazha datetime
,DateLastProdazha datetime
,SummaProdazha decimal(15,2)
,KolProdano decimal(15,2)
,KolKlient int
,KolShet int
,KolPost int
,KolReclamation int
,KolSoputstv int
,KolAnalog int
)
insert into @Table(
ProductID
,DateFirstProdazha
,DateLastProdazha
,SummaProdazha
,KolProdano
,KolKlient
,KolShet
)
select
a131.ObjectID
,MIN(p2277)--дата первой продажи
,MAX(p2277)--дата последней продажи
,SUM(case
when a131.p898 = a230.p2438 then p2461
when a131.P898 = dbo.AXI_BaseCurrency() then a230.p2466
else cast(a230.p2461*a230.p2439/dbo.AXI_SelectExchange(a131.P898,getdate()) AS decimal(15,2))
end)--сумма продано
,SUM(a230.P4175)--количество проданного в осн.ед.изм.
,COUNT(Distinct a229.p2279)--количество контрагентов
,COUNT(distinct a229.ObjectID)--количество счетов
from dbo.Attr131 a131
inner join dbo.Attr230 a230 on a230.P2327 = a131.ObjectID
inner join dbo.Attr229 a229 on a229.ObjectID = a230.P2325
where a229.p2278 in (246)-- подписан
group by a131.ObjectID
update b0
set KolPost = (select COUNT(*) from dbo.Attr154 where p908 = b0.ProductID)
,KolReclamation = (select COUNT(*) from dbo.Attr118 where p1404 = b0.ProductID)
,KolSoputstv = (select COUNT(*) from dbo.Attr208 where p1655 = b0.ProductID)
,KolAnalog = (select COUNT(*) from dbo.Attr207 where p1647 = b0.ProductID)
,KolShet = (select COUNT(*) from dbo.Attr130 a130
inner join dbo.Attr129 a129 on a129.ObjectID = a130.P628
where a129.p664 in (17,16)-- ожидает оплаты, оплачен
and a130.P631 = b0.ProductID)
from @Table b0
insert into @Table(
ProductID
,DateFirstProdazha
,DateLastProdazha
,SummaProdazha
,KolProdano
,KolKlient
,KolShet
)
select
ProductID
,DateFirstProdazha
,DateLastProdazha
,0
,0
,0
,0
from @Table b0
Right join dbo.Attr131 a131 on b0.ProductID = a131.ObjectID
where b0.ProductID IS NULL
update a131
set
p1855 = DateFirstProdazha--Дата первой продажи
,p1856 = DateLastProdazha--Дата посл. продажи
,p1858 = SummaProdazha--Сумма всех продаж
,p1859 = KolProdano--проданное кол-во
,p1860 = KolKlient--КОличество клиентов
,p1864 = KolShet--Количество счетов
,p1861 = KolPost
,p1863 = KolReclamation
,p1862 = KolAnalog
,p1865 = KolSoputstv
from @Table b0
inner join dbo.Attr131 a131 on a131.ObjectID = b0.ProductID
END
as
begin
set nocount on;
/*#Table1 - справочник номенклатуры*/
declare @Table table
(ProductID int
,DateFirstProdazha datetime
,DateLastProdazha datetime
,SummaProdazha decimal(15,2)
,KolProdano decimal(15,2)
,KolKlient int
,KolShet int
,KolPost int
,KolReclamation int
,KolSoputstv int
,KolAnalog int
)
insert into @Table(
ProductID
,DateFirstProdazha
,DateLastProdazha
,SummaProdazha
,KolProdano
,KolKlient
,KolShet
)
select
a131.ObjectID
,MIN(p2277)--дата первой продажи
,MAX(p2277)--дата последней продажи
,SUM(case
when a131.p898 = a230.p2438 then p2461
when a131.P898 = dbo.AXI_BaseCurrency() then a230.p2466
else cast(a230.p2461*a230.p2439/dbo.AXI_SelectExchange(a131.P898,getdate()) AS decimal(15,2))
end)--сумма продано
,SUM(a230.P4175)--количество проданного в осн.ед.изм.
,COUNT(Distinct a229.p2279)--количество контрагентов
,COUNT(distinct a229.ObjectID)--количество счетов
from dbo.Attr131 a131
inner join dbo.Attr230 a230 on a230.P2327 = a131.ObjectID
inner join dbo.Attr229 a229 on a229.ObjectID = a230.P2325
where a229.p2278 in (246)-- подписан
group by a131.ObjectID
update b0
set KolPost = (select COUNT(*) from dbo.Attr154 where p908 = b0.ProductID)
,KolReclamation = (select COUNT(*) from dbo.Attr118 where p1404 = b0.ProductID)
,KolSoputstv = (select COUNT(*) from dbo.Attr208 where p1655 = b0.ProductID)
,KolAnalog = (select COUNT(*) from dbo.Attr207 where p1647 = b0.ProductID)
,KolShet = (select COUNT(*) from dbo.Attr130 a130
inner join dbo.Attr129 a129 on a129.ObjectID = a130.P628
where a129.p664 in (17,16)-- ожидает оплаты, оплачен
and a130.P631 = b0.ProductID)
from @Table b0
insert into @Table(
ProductID
,DateFirstProdazha
,DateLastProdazha
,SummaProdazha
,KolProdano
,KolKlient
,KolShet
)
select
ProductID
,DateFirstProdazha
,DateLastProdazha
,0
,0
,0
,0
from @Table b0
Right join dbo.Attr131 a131 on b0.ProductID = a131.ObjectID
where b0.ProductID IS NULL
update a131
set
p1855 = DateFirstProdazha--Дата первой продажи
,p1856 = DateLastProdazha--Дата посл. продажи
,p1858 = SummaProdazha--Сумма всех продаж
,p1859 = KolProdano--проданное кол-во
,p1860 = KolKlient--КОличество клиентов
,p1864 = KolShet--Количество счетов
,p1861 = KolPost
,p1863 = KolReclamation
,p1862 = KolAnalog
,p1865 = KolSoputstv
from @Table b0
inner join dbo.Attr131 a131 on a131.ObjectID = b0.ProductID
END
Для аналитик по всем продуктам поправил, вот еще один скрипт
Нужно еще "пересчитать аналитики" по продуктам
Когда скрипт прогоняли, базу свою выбирали? Вот здесь?
USE [kk_trade]
GO
/****** Object: StoredProcedure [dbo].[AXI_NomenklaturaRecountAnalitikaAll] Script Date: 07/13/2014 21:14:00 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER procedure [dbo].[AXI_NomenklaturaRecountAnalitikaAll]
as
begin
set nocount on;
/*#Table1 - справочник номенклатуры*/
declare @Table table
(ProductID int
,DateFirstProdazha datetime
,DateLastProdazha datetime
,SummaProdazha decimal(15,2)
,KolProdano decimal(15,2)
,KolKlient int
,KolShet int
,KolPost int
,KolReclamation int
,KolSoputstv int
,KolAnalog int
)
insert into @Table(
ProductID
,DateFirstProdazha
,DateLastProdazha
,SummaProdazha
,KolProdano
,KolKlient
,KolShet
)
select
a131.ObjectID
,MIN(p2277)--дата первой продажи
,MAX(p2277)--дата последней продажи
,SUM(case
when a131.p898 = a230.p2438 then p2461
when a131.P898 = dbo.AXI_BaseCurrency() then a230.p2466
else cast(a230.p2461*a230.p2439/dbo.AXI_SelectExchange(a131.P898,getdate()) AS decimal(15,2))
end)--сумма продано
,SUM(a230.P4175)--количество проданного в осн.ед.изм.
,COUNT(Distinct a229.p2279)--количество контрагентов
,COUNT(distinct a229.ObjectID)--количество счетов
from dbo.Attr131 a131
inner join dbo.Attr230 a230 on a230.P2327 = a131.ObjectID
inner join dbo.Attr229 a229 on a229.ObjectID = a230.P2325
where a229.p2278 in (246)-- подписан
group by a131.ObjectID
update b0
set KolPost = (select COUNT(*) from dbo.Attr154 where p908 = b0.ProductID)
,KolReclamation = (select COUNT(*) from dbo.Attr118 where p1404 = b0.ProductID)
,KolSoputstv = (select COUNT(*) from dbo.Attr208 where p1655 = b0.ProductID)
,KolAnalog = (select COUNT(*) from dbo.Attr207 where p1647 = b0.ProductID)
,KolShet = (select COUNT(*) from dbo.Attr130 a130
inner join dbo.Attr129 a129 on a129.ObjectID = a130.P628
where a129.p664 in (17,16)-- ожидает оплаты, оплачен
and a130.P631 = b0.ProductID)
from @Table b0
insert into @Table(
ProductID
,DateFirstProdazha
,DateLastProdazha
,SummaProdazha
,KolProdano
,KolKlient
,KolShet
)
select
ProductID
,DateFirstProdazha
,DateLastProdazha
,0
,0
,0
,0
from @Table b0
Right join #Table1 b1 on b0.ProductID = b1.ObjectID
where b0.ProductID IS NULL
update a131
set
p1855 = DateFirstProdazha--Дата первой продажи
,p1856 = DateLastProdazha--Дата посл. продажи
,p1858 = SummaProdazha--Сумма всех продаж
,p1859 = KolProdano--проданное кол-во
,p1860 = KolKlient--КОличество клиентов
,p1864 = KolShet--Количество счетов
,p1861 = KolPost
,p1863 = KolReclamation
,p1862 = KolAnalog
,p1865 = KolSoputstv
from @Table b0
inner join dbo.Attr131 a131 on a131.ObjectID = b0.ProductID
END
GO
/****** Object: StoredProcedure [dbo].[AXI_NomenklaturaRecountAnalitikaAll] Script Date: 07/13/2014 21:14:00 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER procedure [dbo].[AXI_NomenklaturaRecountAnalitikaAll]
as
begin
set nocount on;
/*#Table1 - справочник номенклатуры*/
declare @Table table
(ProductID int
,DateFirstProdazha datetime
,DateLastProdazha datetime
,SummaProdazha decimal(15,2)
,KolProdano decimal(15,2)
,KolKlient int
,KolShet int
,KolPost int
,KolReclamation int
,KolSoputstv int
,KolAnalog int
)
insert into @Table(
ProductID
,DateFirstProdazha
,DateLastProdazha
,SummaProdazha
,KolProdano
,KolKlient
,KolShet
)
select
a131.ObjectID
,MIN(p2277)--дата первой продажи
,MAX(p2277)--дата последней продажи
,SUM(case
when a131.p898 = a230.p2438 then p2461
when a131.P898 = dbo.AXI_BaseCurrency() then a230.p2466
else cast(a230.p2461*a230.p2439/dbo.AXI_SelectExchange(a131.P898,getdate()) AS decimal(15,2))
end)--сумма продано
,SUM(a230.P4175)--количество проданного в осн.ед.изм.
,COUNT(Distinct a229.p2279)--количество контрагентов
,COUNT(distinct a229.ObjectID)--количество счетов
from dbo.Attr131 a131
inner join dbo.Attr230 a230 on a230.P2327 = a131.ObjectID
inner join dbo.Attr229 a229 on a229.ObjectID = a230.P2325
where a229.p2278 in (246)-- подписан
group by a131.ObjectID
update b0
set KolPost = (select COUNT(*) from dbo.Attr154 where p908 = b0.ProductID)
,KolReclamation = (select COUNT(*) from dbo.Attr118 where p1404 = b0.ProductID)
,KolSoputstv = (select COUNT(*) from dbo.Attr208 where p1655 = b0.ProductID)
,KolAnalog = (select COUNT(*) from dbo.Attr207 where p1647 = b0.ProductID)
,KolShet = (select COUNT(*) from dbo.Attr130 a130
inner join dbo.Attr129 a129 on a129.ObjectID = a130.P628
where a129.p664 in (17,16)-- ожидает оплаты, оплачен
and a130.P631 = b0.ProductID)
from @Table b0
insert into @Table(
ProductID
,DateFirstProdazha
,DateLastProdazha
,SummaProdazha
,KolProdano
,KolKlient
,KolShet
)
select
ProductID
,DateFirstProdazha
,DateLastProdazha
,0
,0
,0
,0
from @Table b0
Right join #Table1 b1 on b0.ProductID = b1.ObjectID
where b0.ProductID IS NULL
update a131
set
p1855 = DateFirstProdazha--Дата первой продажи
,p1856 = DateLastProdazha--Дата посл. продажи
,p1858 = SummaProdazha--Сумма всех продаж
,p1859 = KolProdano--проданное кол-во
,p1860 = KolKlient--КОличество клиентов
,p1864 = KolShet--Количество счетов
,p1861 = KolPost
,p1863 = KolReclamation
,p1862 = KolAnalog
,p1865 = KolSoputstv
from @Table b0
inner join dbo.Attr131 a131 on a131.ObjectID = b0.ProductID
END
/****** Object: StoredProcedure [dbo].[AXI_NomenklaturaRecountAnalitikaOne] Script Date: 07/13/2014 20:14:30 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER procedure [dbo].[AXI_NomenklaturaRecountAnalitikaOne]
as
begin
set nocount on;
/*#Table1 - справочник номенклатуры*/
declare @Table table
(ProductID int
,DateFirstProdazha datetime
,DateLastProdazha datetime
,SummaProdazha decimal(15,2)
,KolProdano decimal(15,2)
,KolKlient int
,KolShet int
,KolPost int
,KolReclamation int
,KolSoputstv int
,KolAnalog int
)
insert into @Table(
ProductID
,DateFirstProdazha
,DateLastProdazha
,SummaProdazha
,KolProdano
,KolKlient
,KolShet
)
select
a131.ObjectID
,MIN(p2277)--дата первой продажи
,MAX(p2277)--дата последней продажи
,SUM(case
when a131.p898 = a230.p2438 then p2461
when a131.P898 = dbo.AXI_BaseCurrency() then a230.p2466
else cast(a230.p2461*a230.p2439/dbo.AXI_SelectExchange(a131.P898,getdate()) AS decimal(15,2))
end)--сумма продано
,SUM(a230.P4175)--количество проданного в осн.ед.изм.
,COUNT(Distinct a229.p2279)--количество контрагентов
,COUNT(distinct a229.ObjectID)--количество счетов
from #Table1 b0
inner join dbo.Attr131 a131 on b0.ObjectID = a131.ObjectID
inner join dbo.Attr230 a230 on a230.P2327 = a131.ObjectID
inner join dbo.Attr229 a229 on a229.ObjectID = a230.P2325
where a229.p2278 in (246)--подписан
group by a131.ObjectID
update b0
set KolPost = (select COUNT(*) from dbo.Attr154 where p908 = b0.ProductID)
,KolReclamation = (select COUNT(*) from dbo.Attr118 where p1404 = b0.ProductID)
,KolSoputstv = (select COUNT(*) from dbo.Attr208 where p1655 = b0.ProductID)
,KolAnalog = (select COUNT(*) from dbo.Attr207 where p1647 = b0.ProductID)
,KolShet = (select COUNT(*) from dbo.Attr130 a130
inner join dbo.Attr129 a129 on a129.ObjectID = a130.P628
where a129.p664 in (17,16)-- ожидает оплаты, оплачен
and a130.P631 = b0.ProductID)
from @Table b0
insert into @Table(
ProductID
,DateFirstProdazha
,DateLastProdazha
,SummaProdazha
,KolProdano
,KolKlient
,KolShet
)
select
ProductID
,DateFirstProdazha
,DateLastProdazha
,0
,0
,0
,0
from @Table b0
Right join #Table1 b1 on b0.ProductID = b1.ObjectID
where b0.ProductID IS NULL
update a131
set
p1855 = DateFirstProdazha--Дата первой продажи
,p1856 = DateLastProdazha--Дата посл. продажи
,p1858 = SummaProdazha--Сумма всех продаж
,p1859 = KolProdano--проданное кол-во
,p1860 = KolKlient--КОличество клиентов
,p1864 = KolShet--Количество счетов
,p1861 = KolPost
,p1863 = KolReclamation
,p1862 = KolAnalog
,p1865 = KolSoputstv
from @Table b0
inner join dbo.Attr131 a131 on a131.ObjectID = b0.ProductID
END
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER procedure [dbo].[AXI_NomenklaturaRecountAnalitikaOne]
as
begin
set nocount on;
/*#Table1 - справочник номенклатуры*/
declare @Table table
(ProductID int
,DateFirstProdazha datetime
,DateLastProdazha datetime
,SummaProdazha decimal(15,2)
,KolProdano decimal(15,2)
,KolKlient int
,KolShet int
,KolPost int
,KolReclamation int
,KolSoputstv int
,KolAnalog int
)
insert into @Table(
ProductID
,DateFirstProdazha
,DateLastProdazha
,SummaProdazha
,KolProdano
,KolKlient
,KolShet
)
select
a131.ObjectID
,MIN(p2277)--дата первой продажи
,MAX(p2277)--дата последней продажи
,SUM(case
when a131.p898 = a230.p2438 then p2461
when a131.P898 = dbo.AXI_BaseCurrency() then a230.p2466
else cast(a230.p2461*a230.p2439/dbo.AXI_SelectExchange(a131.P898,getdate()) AS decimal(15,2))
end)--сумма продано
,SUM(a230.P4175)--количество проданного в осн.ед.изм.
,COUNT(Distinct a229.p2279)--количество контрагентов
,COUNT(distinct a229.ObjectID)--количество счетов
from #Table1 b0
inner join dbo.Attr131 a131 on b0.ObjectID = a131.ObjectID
inner join dbo.Attr230 a230 on a230.P2327 = a131.ObjectID
inner join dbo.Attr229 a229 on a229.ObjectID = a230.P2325
where a229.p2278 in (246)--подписан
group by a131.ObjectID
update b0
set KolPost = (select COUNT(*) from dbo.Attr154 where p908 = b0.ProductID)
,KolReclamation = (select COUNT(*) from dbo.Attr118 where p1404 = b0.ProductID)
,KolSoputstv = (select COUNT(*) from dbo.Attr208 where p1655 = b0.ProductID)
,KolAnalog = (select COUNT(*) from dbo.Attr207 where p1647 = b0.ProductID)
,KolShet = (select COUNT(*) from dbo.Attr130 a130
inner join dbo.Attr129 a129 on a129.ObjectID = a130.P628
where a129.p664 in (17,16)-- ожидает оплаты, оплачен
and a130.P631 = b0.ProductID)
from @Table b0
insert into @Table(
ProductID
,DateFirstProdazha
,DateLastProdazha
,SummaProdazha
,KolProdano
,KolKlient
,KolShet
)
select
ProductID
,DateFirstProdazha
,DateLastProdazha
,0
,0
,0
,0
from @Table b0
Right join #Table1 b1 on b0.ProductID = b1.ObjectID
where b0.ProductID IS NULL
update a131
set
p1855 = DateFirstProdazha--Дата первой продажи
,p1856 = DateLastProdazha--Дата посл. продажи
,p1858 = SummaProdazha--Сумма всех продаж
,p1859 = KolProdano--проданное кол-во
,p1860 = KolKlient--КОличество клиентов
,p1864 = KolShet--Количество счетов
,p1861 = KolPost
,p1863 = KolReclamation
,p1862 = KolAnalog
,p1865 = KolSoputstv
from @Table b0
inner join dbo.Attr131 a131 on a131.ObjectID = b0.ProductID
END
Разобрались с пересчетом аналитик. Процедура не записывала нулевые значения. Т.е. при клонировании, когда копируются все данные из основной карточки, копировалась и аналитика, процедура же, которая отрабатывалась после этого не обнуляла данные из-за ошибки в ней. Вам нужно открыть SQL Mabagment Studio и прогнать там два следующих скрипта. Не забудьте при выполнении выбрать вашу базу данных
Customer support service by UserEcho