Cari Risklerini Update eden Query

Unity'de herhangi bir sebepten dolayı risk bilgilerinin bozulması durumunda aşağıdaki cursor ile Cari riskleri update edilir.

DECLARE @CLREF INT
DECLARE @DEFINITION_ VARCHAR(150)
DECLARE @TOTAL1 FLOAT
DECLARE @TOTAL2 FLOAT
DECLARE YETKIKODU CURSOR FOR
SELECT LOGICALREF,DEFINITION_ FROM LG_208_CLCARD (NOLOCK) WHERE
CODE LIKE 'M.%' AND LOGICALREF<>1010
ORDER BY DEFINITION_
OPEN YETKIKODU
FETCH NEXT FROM YETKIKODU
INTO @CLREF,@DEFINITION_
WHILE @@FETCH_STATUS = 0
BEGIN
SELECT @TOTAL1=SUM((AMOUNT-SHIPPEDAMOUNT)*PRICE)
+SUM(((AMOUNT-SHIPPEDAMOUNT)*PRICE*VAT)/100)
-SUM((((AMOUNT-SHIPPEDAMOUNT)*PRICE)
+(((AMOUNT-SHIPPEDAMOUNT)*PRICE*VAT)/100))*(DISTDISC/TOTAL))
FROM LG_208_01_ORFLINE ORFL (NOLOCK)
INNER JOIN LG_208_CLCARD (NOLOCK) CL ON ORFL.CLIENTREF=CL.LOGICALREF
WHERE LINETYPE =0 AND CLOSED =0 AND
(AMOUNT-SHIPPEDAMOUNT)>0 AND CL.LOGICALREF=@CLREF
SELECT @TOTAL2=ORDRISKTOTAL FROM LG_208_01_CLRNUMS (NOLOCK)
WHERE CLCARDREF= @CLREF
SET @TOTAL1=FLOOR(@TOTAL1)
SET @TOTAL2=FLOOR(@TOTAL2)
IF @TOTAL2<>@TOTAL1
BEGIN
UPDATE LG_208_01_CLRNUMS SET ORDRISKTOTAL=@TOTAL1 WHERE CLCARDREF= @CLREF
END
FETCH NEXT FROM YETKIKODU
INTO @CLREF,@DEFINITION_
END
CLOSE YETKIKODU
DEALLOCATE YETKIKODU
GO

Hiç yorum yok:

2018 SGK İşten Çıkış Kodları (696 sayılı KHK kapsamında eklenenler dahil)

2018 SGK İşten Çıkış Kodları 1- Deneme süreli iş sözleşmesinin işverence feshi 2- Deneme süreli iş sözleşmesinin işçi tarafından feshi ...