dbo.f_stock_opname

Description

Properties

Name Value
ANSI Nulls ON

True

Quoted Identifier ON

True

Encrypted

False

Execute As
Null on Null Input

False

Schema Bound

False

Assembly

Parameters

Name Data Type Length Description
@tgstart date 3
@tgend date 3
@tipebahan varchar 50

SQL Script

SET QUOTED_IDENTIFIER, ANSI_NULLS ON
GO


create FUNCTION dbo.f_stock_opname
( 
 @tgstart date, @tgend date, @tipebahan varchar(50) 
)
RETURNS @stock_opname TABLE (
kode_barang varchar(50) null, 
qty float null )
--idno bigint identity(1,1),
AS
BEGIN 
-- cek last date
with
 ct_kodebrg (kodebarang, partcustoms, satuan) as
  (
   select kode_barang, nama_barang, satuan from tbl_kode_barang
   
  ) ,
 ct_stock_opname
  (
  partcustoms, qty
   ) as (
  select part_name_customs, sum(qty)
  from tbl_stock_opname
  where typebahan = @tipebahan  
  and date_stock_opname in (select max(date_stock_opname) from tbl_stock_opname where typebahan = @tipebahan and date_stock_opname between  @tgstart and @tgend group by part_no)
  group by part_name_customs
   
  )   
  
 insert into  @stock_opname (
   kode_barang
  ,qty
 
 ) select ct_kodebrg.partcustoms, ct_stock_opname.qty    from ct_kodebrg
   left outer join ct_stock_opname on ct_stock_opname.partcustoms=ct_kodebrg.partcustoms
  
 
 return  
 
END
GO

Used By

No items found