CREATE or alter PROC KdvDegistir_DNMK  @DP NVARCHAR(10)  , @KDV INT ,@FD int
as
--   KdvDegistir_DNMK '5',1,'0'
DECLARE @SQL NVARCHAR(MAX) 
SET @SQL=  
'UPDATE  STOKKARTI SET SatisKdv='+convert(varchar,@KDV)+' WHERE StokNo IN (select StokNo from STOKKARTI WHERE DepartmanKodu='+convert(varchar, @DP)+')'
if @FD =1 
begin
set @SQL=@SQL + ' update StokFiyat set F4Fiyat=(case when F4Kdv = ''H'' then F4Fiyat  else (F4Fiyat/(100 +  SatisKdv)*100)  end )' 
end
 --+
--' WHERE StokNo IN (select StokNo from STOKKARTI WHERE DepartmanKodu='+convert(varchar, @DP)+')' ;
 print @SQL
--select * from STOKKARTI WHERE StokNo IN (select StokNo from STOKKARTI WHERE DepartmanKodu=@DP)

UPDATE  STOKKARTI SET SatisKdv=1 WHERE Kodu IN (select Kodu from STOKKARTI WHERE DepartmanKodu=1) 
UPDATE  StokFiyat  SET SatisKdv=1    WHERE Kodu IN (select Kodu from STOKKARTI SK WHERE DepartmanKodu=1 )
update StokFiyat set F4Fiyat=(case when F4Kdv = 'H' then F4Fiyat  else (F4Fiyat/(100 +  SatisKdv)*100)  end )
update STOKKARTI SET F4Fiyat=(case when F4Kdv = 'H' then F4Fiyat  else (F4Fiyat/(100 +  SatisKdv)*100)  end )


UPDATE  STOKKARTI  SET SatisKdv=1 ,AlisKdv=1   WHERE Kodu IN (select Kodu from STOKKARTI SK WHERE DepartmanKodu=1 )
UPDATE  StokFiyat  SET SatisKdv=1    WHERE Kodu IN (select Kodu from STOKKARTI SK WHERE DepartmanKodu=1 )


--UPDATE STOKKARTI SET SatisKdv=@KDV WHERE StokNo IN (
--select StokNo from STOKKARTI WHERE DepartmanKodu=@DP)

--update StokFiyat set F4Fiyat=(case when F4Kdv = 'H' then F4Fiyat  else (F4Fiyat/(100 +  SatisKdv)*100)  end ) WHERE StokNo IN (
-- select StokNo,* from STOKKARTI WHERE DepartmanKodu='5'  )

--F4FiyatH where   F4Kdv='H'
--update StokFiyat set F4Fiyat=F4FiyatH*( SatisKdv+100)/100   where   F4Kdv='D'

--  @F1FiyatH  = (case when F1Kdv = 'H' then F1Fiyat  else (F1Fiyat/(100 +  SatisKdv)*100)  end ),


--select TOP 1 * from STOKKARTI

--  UPDATE  STOKKARTI SET SatisKdv=1 WHERE StokNo IN (select StokNo from STOKKARTI WHERE DepartmanKodu=5)


DECLARE @SK NVARCHAR(50)
SET @SK='8690632084008'
SELECT * FROM StokFiyat WHERE Kodu=@SK
SELECT * FROM STOKKARTI WHERE Kodu=@SK