Вниз
Скачать: CL | DM;

Подскажите плз как это будет в Interbase SQL   Найти похожие ветки 

← →
HMT   (2004-08-17 10:26) [0]

Это текст процедуры MS-SQL, уже три дня пытаюсь перести его в interbase. Смысл скрипта - суммирование прихода, вычитание расхода для получения остатков. Помогите плз, если кто синтаксис знает.

DELETE FROM Results

INSERT INTO Results SELECT DISTINCT(ProductName), SUM(Quantity) as Quantity from Inbound GROUP BY ProductName

DECLARE @ProductName varchar(500)
DECLARE @Discount int
DECLARE CT CURSOR FOR SELECT DISTINCT(ProductName), SUM(Discount) as Discount from Outbound GROUP BY ProductName

OPEN CT
WHILE 1=1 BEGIN
 FETCH FROM CT INTO @ProductName, @Discount

 IF @@fetch_status=-1
     BREAK
 IF @@fetch_status=-2
     CONTINUE

 UPDATE Results SET Quantity=Quantity-@Discount WHERE ProductName=@ProductName
END

DEALLOCATE CT
SELECT * FROM Inbound
SELECT * FROM Outbound
SELECT * FROM Results


← →
HMT   (2004-08-17 10:38) [1]

Может курсор здесь лишний ?

Чем можно заменить fetch_status?


← →
Соловьев ©   (2004-08-17 10:41) [2]


> DECLARE CT CURSOR FOR SELECT DISTINCT(ProductName), SUM(Discount)
> as Discount from Outbound GROUP BY ProductName
>
> OPEN CT
> WHILE 1=1 BEGIN
>  FETCH FROM CT INTO @ProductName, @Discount
>
>  IF @@fetch_status=-1
>      BREAK
>  IF @@fetch_status=-2
>      CONTINUE
>
>  UPDATE Results SET Quantity=Quantity-@Discount WHERE ProductName=@ProductName
> END

насколь я понял тут основной трабл?
for
SELECT DISTINCT(ProductName), SUM(Discount) as Discount from Outbound GROUP BY ProductName
into :ProductName, :Discount
do begin
 UPDATE Results SET Quantity=Quantity-:Discount WHERE ProductName=:ProductName;
end;


← →
Соловьев ©   (2004-08-17 10:42) [3]


> Чем можно заменить fetch_status?

нету такого


← →
HMT   (2004-08-17 10:42) [4]

Да, тут.

thankz..щас попробую


← →
Sandman25 ©   (2004-08-17 11:01) [5]

Кстати, на MSSQL вместо ХП надо было написать:
select productname, sum(discount)
from
(
select productname, sum(discount) discount
 from inbound
 group by productname
union all
select productname, -sum(discount) discount
 from outbound
 group by productname
) a
group by productname


← →
Sandman25 ©   (2004-08-17 11:03) [6]

Или даже

select productname, sum(discount)
from
(
select productname, discount
from inbound
union all
select productname, -discount
from outbound
) a
group by productname



Страницы: 1 вся ветка

Скачать: CL | DM;



Память: 0.46 MB
Время: 0.025 c
1-1093697729
<b>He`KTo</b>
2004-08-28 16:55
2004.09.12
Как Icon (Icon:hIcon) запихать в ImageList


1-1093453939
zep
2004-08-25 21:12
2004.09.12
StringGrid


1-1093616182
GrayFace
2004-08-27 18:16
2004.09.12
Компонент, как published property Компонента


8-1087797092
hogo
2004-06-21 09:51
2004.09.12
Timage


1-1093861033
saska
2004-08-30 14:17
2004.09.12
про Мессаги




   Наверх