Description
Properties
| Name | Value |
|---|---|
| ANSI Nulls ON | True |
| Quoted Identifier ON | True |
| Encrypted | False |
| Execute As | |
| Assembly |
Parameters
| Name | Data Type | Length | Description |
|---|---|---|---|
| @PARAMETER | xml | -1 | |
| @XMLMAPING | xml | -1 | |
| @fixWhere | varchar | 2000 | |
| @Sort | varchar | 255 | |
| @desc | bit | 1 | |
| @OutSortBy | varchar | 255 | |
| @rumusWhere | varchar | -1 | |
| @search | xml | -1 |
SQL Script
SET QUOTED_IDENTIFIER, ANSI_NULLS ON
GO
create procedure dbo.MyRUMUSWhereAndSortView
@PARAMETER xml,
@XMLMAPING xml,
@fixWhere varchar(2000),
@Sort varchar(255) ,
@desc bit,
@OutSortBy varchar(255) output,
@rumusWhere varchar(max) output,
@search xml output
WITH
---XencX---encryption,
EXECUTE AS CALLER
AS
BEGIN
set nocount on
declare @searchX table(xid varchar(3), isi varchar(255));
declare @tblMapping table (
ifield varchar(255) primary key,
iname varchar(max),
iBolehSearch bit ,
iSearchtype int , --= 1= STRING ,2=ANGKA , 3=DATETIME,
iSearchByPassLike bit)
declare @ifield varchar(255) ,
@iname varchar(255),
@iBolehSearch bit ,
@iSearchtype int , --= 1= STRING ,2=ANGKA , 3=DATETIME,
@iSearchByPassLike bit
insert into @tblMapping
SELECT
isnull(tempTable.xItem.value('@ifield', 'varchar(255)'),'') as ifield,
isnull(tempTable.xItem.value('@iname', 'varchar(max)'),'') as iname,
isnull(tempTable.xItem.value('@iBolehSearch', 'bit'),0) as iBolehSearch ,
isnull(tempTable.xItem.value('@iSearchtype', 'int'),1) as iSearchtype,
isnull(tempTable.xItem.value('@iSearchByPassLike', 'varchar(255)'),0) as iSearchByPassLike
FROM @XMLMAPING.nodes('fl/r') tempTable(xItem)
declare
@x_rID varchar(255),
@x_cr bit,
@x_lr bit,
@x_ll bit,
@x_ft varchar(255),
@x_ft2 varchar(255),
@x_cn int,
@RESULT1 varchar(1000) ,
@RESULT2 varchar(1000)
set @rumusWhere=''
set @rumusWhere=@rumusWhere + @fixWhere
DECLARE xSearch CURSOR FOR
SELECT
isnull(tempTable.xItem.value('@rID', 'varchar(255)'),'') ,
isnull(tempTable.xItem.value('@cr', 'bit'),0) ,
isnull(tempTable.xItem.value('@lr', 'bit'),0) ,
isnull(tempTable.xItem.value('@ll', 'bit'),0) ,
isnull(tempTable.xItem.value('@ft', 'varchar(255)'),'') ,
isnull(tempTable.xItem.value('@ft2', 'varchar(255)'),'') ,
isnull(tempTable.xItem.value('@cn', 'int'),1)
FROM @PARAMETER.nodes('param/search/r') tempTable(xItem)
OPEN xSearch;
FETCH NEXT FROM xSearch INTO
@x_rID ,
@x_cr ,
@x_lr ,
@x_ll ,
@x_ft ,
@x_ft2 ,
@x_cn ;
WHILE @@FETCH_STATUS = 0
BEGIN
select top 1
@ifield= ifield,
@iname =iname ,
@iBolehSearch =iBolehSearch ,
@iSearchtype =iSearchtype , --= 1= STRING ,2=ANGKA , 3=DATETIME,
@iSearchByPassLike =iSearchByPassLike
from @tblMapping where ifield=@x_rID
if @iBolehSearch =1
begin
EXEC [dbo].[OlahFindViewType2]
@PATH =@ifield,
@FIELD_TABLE = @iname,
@TYPE =@iSearchtype,
@BYPASS_LIKE = @iSearchByPassLike,
@x_cr = @x_cr,
@x_lr = @x_lr,
@x_ll = @x_ll,
@x_ft =@x_ft,
@x_ft2 =@x_ft2,
@x_cn = @x_cn,
@RESULT1 = @RESULT1 OUTPUT,
@RESULT2 = @RESULT2 OUTPUT
if LEN(@RESULT1)>0
begin
set @rumusWhere=@rumusWhere + @RESULT1
insert into @searchX (xid,isi) values (@ifield, ltrim(rtrim(@RESULT2)));
end
end
FETCH NEXT FROM xSearch INTO
@x_rID ,
@x_cr ,
@x_lr ,
@x_ll ,
@x_ft ,
@x_ft2 ,
@x_cn ;
END;
CLOSE xSearch;
DEALLOCATE xSearch
if nullif(@Sort,'') is null
begin
select top 1 @OutSortBy=iname ,@Sort=ifield from @tblMapping
end
else
begin
set @OutSortBy=(select top 1 iname from @tblMapping where ifield =@Sort )
if @OutSortBy is null
begin
set @Sort='rID';
set @OutSortBy=(select top 1 iname from @tblMapping where ifield =@Sort )
if @OutSortBy is null
begin
select top 1 @OutSortBy=iname ,@Sort=ifield from @tblMapping
end
end
end
if (@desc=1) set @OutSortBy= @OutSortBy + ' desc '
set @search =(select xid as '@id',isi as '@isi' from @searchx for xml path('fl'))
if (LEN(@rumusWhere)>0) set @rumusWhere= ' where ' + SUBSTRING ( @rumusWhere ,0,LEN( @rumusWhere)-3);
set nocount off
END
GO
GO
create procedure dbo.MyRUMUSWhereAndSortView
@PARAMETER xml,
@XMLMAPING xml,
@fixWhere varchar(2000),
@Sort varchar(255) ,
@desc bit,
@OutSortBy varchar(255) output,
@rumusWhere varchar(max) output,
@search xml output
WITH
---XencX---encryption,
EXECUTE AS CALLER
AS
BEGIN
set nocount on
declare @searchX table(xid varchar(3), isi varchar(255));
declare @tblMapping table (
ifield varchar(255) primary key,
iname varchar(max),
iBolehSearch bit ,
iSearchtype int , --= 1= STRING ,2=ANGKA , 3=DATETIME,
iSearchByPassLike bit)
declare @ifield varchar(255) ,
@iname varchar(255),
@iBolehSearch bit ,
@iSearchtype int , --= 1= STRING ,2=ANGKA , 3=DATETIME,
@iSearchByPassLike bit
insert into @tblMapping
SELECT
isnull(tempTable.xItem.value('@ifield', 'varchar(255)'),'') as ifield,
isnull(tempTable.xItem.value('@iname', 'varchar(max)'),'') as iname,
isnull(tempTable.xItem.value('@iBolehSearch', 'bit'),0) as iBolehSearch ,
isnull(tempTable.xItem.value('@iSearchtype', 'int'),1) as iSearchtype,
isnull(tempTable.xItem.value('@iSearchByPassLike', 'varchar(255)'),0) as iSearchByPassLike
FROM @XMLMAPING.nodes('fl/r') tempTable(xItem)
declare
@x_rID varchar(255),
@x_cr bit,
@x_lr bit,
@x_ll bit,
@x_ft varchar(255),
@x_ft2 varchar(255),
@x_cn int,
@RESULT1 varchar(1000) ,
@RESULT2 varchar(1000)
set @rumusWhere=''
set @rumusWhere=@rumusWhere + @fixWhere
DECLARE xSearch CURSOR FOR
SELECT
isnull(tempTable.xItem.value('@rID', 'varchar(255)'),'') ,
isnull(tempTable.xItem.value('@cr', 'bit'),0) ,
isnull(tempTable.xItem.value('@lr', 'bit'),0) ,
isnull(tempTable.xItem.value('@ll', 'bit'),0) ,
isnull(tempTable.xItem.value('@ft', 'varchar(255)'),'') ,
isnull(tempTable.xItem.value('@ft2', 'varchar(255)'),'') ,
isnull(tempTable.xItem.value('@cn', 'int'),1)
FROM @PARAMETER.nodes('param/search/r') tempTable(xItem)
OPEN xSearch;
FETCH NEXT FROM xSearch INTO
@x_rID ,
@x_cr ,
@x_lr ,
@x_ll ,
@x_ft ,
@x_ft2 ,
@x_cn ;
WHILE @@FETCH_STATUS = 0
BEGIN
select top 1
@ifield= ifield,
@iname =iname ,
@iBolehSearch =iBolehSearch ,
@iSearchtype =iSearchtype , --= 1= STRING ,2=ANGKA , 3=DATETIME,
@iSearchByPassLike =iSearchByPassLike
from @tblMapping where ifield=@x_rID
if @iBolehSearch =1
begin
EXEC [dbo].[OlahFindViewType2]
@PATH =@ifield,
@FIELD_TABLE = @iname,
@TYPE =@iSearchtype,
@BYPASS_LIKE = @iSearchByPassLike,
@x_cr = @x_cr,
@x_lr = @x_lr,
@x_ll = @x_ll,
@x_ft =@x_ft,
@x_ft2 =@x_ft2,
@x_cn = @x_cn,
@RESULT1 = @RESULT1 OUTPUT,
@RESULT2 = @RESULT2 OUTPUT
if LEN(@RESULT1)>0
begin
set @rumusWhere=@rumusWhere + @RESULT1
insert into @searchX (xid,isi) values (@ifield, ltrim(rtrim(@RESULT2)));
end
end
FETCH NEXT FROM xSearch INTO
@x_rID ,
@x_cr ,
@x_lr ,
@x_ll ,
@x_ft ,
@x_ft2 ,
@x_cn ;
END;
CLOSE xSearch;
DEALLOCATE xSearch
if nullif(@Sort,'') is null
begin
select top 1 @OutSortBy=iname ,@Sort=ifield from @tblMapping
end
else
begin
set @OutSortBy=(select top 1 iname from @tblMapping where ifield =@Sort )
if @OutSortBy is null
begin
set @Sort='rID';
set @OutSortBy=(select top 1 iname from @tblMapping where ifield =@Sort )
if @OutSortBy is null
begin
select top 1 @OutSortBy=iname ,@Sort=ifield from @tblMapping
end
end
end
if (@desc=1) set @OutSortBy= @OutSortBy + ' desc '
set @search =(select xid as '@id',isi as '@isi' from @searchx for xml path('fl'))
if (LEN(@rumusWhere)>0) set @rumusWhere= ' where ' + SUBSTRING ( @rumusWhere ,0,LEN( @rumusWhere)-3);
set nocount off
END
GO
Depends On
1Used By
45- dbo.MG_MONITORING_SUAI
- dbo.MG_MS_ADJUSTMEN_SOURCE
- dbo.MG_MS_ADJUSTMENT_DETAIL
- dbo.MG_MS_ADJUSTMENT_ITEM
- dbo.MG_MS_BASE_PART
- dbo.MG_MS_BASE_PART_FOR_IMPORT_REPORT_CAR_LINE
- dbo.MG_MS_BC_IN_DOCUMENT
- dbo.MG_MS_CAR_LINE
- dbo.MG_MS_MEMO_DETAIL
- dbo.MG_MS_MOLTS_GRN
- dbo.MG_MS_MOLTS_INVOICE_ITEM
- dbo.MG_MS_OUT_CHANGE_PART_LIST_DETAIL
- dbo.MG_MS_OUT_PRODUCTION_PART_LIST_DETAIL
- dbo.MG_MS_PART_LIST_UPLOAD
- dbo.MG_MS_STO_DETAIL
- dbo.MG_MS_STO_SOURCE
- dbo.MG_MS_SUPPLIER_CUSTOMER
- dbo.MG_MS_TEKNISI
- dbo.MG_MS_TYPE_PROCCESS
- dbo.MG_PEMI_RPT_261
- dbo.MG_PEMI_RPT_262
- dbo.MG_PEMI_RPT_BC23
- dbo.MG_PEMI_RPT_BC25
- dbo.MG_PEMI_RPT_BC27_IN
- dbo.MG_PEMI_RPT_BC27_OUT
- dbo.MG_PEMI_RPT_BC30
- dbo.MG_PEMI_RPT_BC40
- dbo.MG_PEMI_RPT_BC41
- dbo.MG_PEMI_RPT_KB_DPIL
- dbo.MG_PEMI_RPT_KB_EKONOMI
- dbo.MG_PEMI_RPT_KB_EKSPOR
- dbo.MG_PEMI_RPT_KB_KB
- dbo.MG_PEMI_RPT_RETURN
- dbo.MG_PEMI_RPT_rpMonthlyIncoming_BC23
- dbo.MG_PEMI_RPT_rpMonthlyOutgoing_BC30
- dbo.RPT_DYNAMIC_BARANG_PER_DOKUMENT_IN
- dbo.RPT_DYNAMIC_BARANG_PER_DOKUMENT_IN_AW_2340
- dbo.RPT_DYNAMIC_BARANG_PER_DOKUMENT_IN_AW_2340_FIX
- dbo.RPT_DYNAMIC_BARANG_PER_DOKUMENT_OUT
- dbo.RPT_DYNAMIC_MUTASI_BAHAN_BAKU
- dbo.RPT_DYNAMIC_MUTASI_BARANG_JADI
- dbo.RPT_DYNAMIC_MUTASI_MESIN
- dbo.RPT_DYNAMIC_MUTASI_MESIN_TEST
- dbo.RPT_DYNAMIC_MUTASI_SCRAP
- dbo.RPT_DYNAMIC_WIP