1. Cari jumlah barang di faktur tertentu dengan parameter NoFJ(tipenya integer)
Create FUNCTION JumlahBarang
(
@p1 nvarchar(12)
)
RETURNS nvarchar(12)
AS
BEGIN
DECLARE @Result int
SELECT @Result = count(kodebarang) from FJDet
where NoFJ = @p1
RETURN @Result
END
GO
select distinct dbo.JumlahBarang('FJ-0000001') from FJ
2. Cari Total Qty*Harga dari tabel FJDet, parameternya NoFJ(tipenya money)
Create FUNCTION QmH
(
@p1 nvarchar(12)
)
RETURNS nvarchar(12)
AS
BEGIN
DECLARE @Result money
SELECT @Result = SUM(Qty * Harga) from FJDet
where NoFJ = @p1
RETURN @Result
END
GO
select distinct nofj,dbo.QmH(noFJ) from FJDet
3. Jumlah Nama Barang mengandung kata tertentu pada tabel Baran, parameternya Nama Barang (tipenya integer)
1. Create FUNCTION JumlahBarang
(
@p1 nvarchar(50)
)
RETURNS nvarchar(50)
AS
BEGIN
DECLARE @Result int
SELECT @Result = count(namabarang) from barang
where namabarang like '%'+@p1+'%'
(
@p1 nvarchar(50)
)
RETURNS nvarchar(50)
AS
BEGIN
DECLARE @Result int
SELECT @Result = count(namabarang) from barang
where namabarang like '%'+@p1+'%'
RETURN @Result
END
GO
Create FUNCTION KurangDari
(
@x int
)
RETURNS int
AS
BEGIN
DECLARE @Result int
SELECT @Result = count(stok) from Barang
Where Stok <= @x
RETURN @Result
END
GO
select distinct dbo.KurangDari(2) from barang
Tidak ada komentar:
Posting Komentar