create the Store Procedure create Dynamic Query and Paging
Here we Create Store Procedure For the Create the Dynamic Query and also paging and also insert data when page no is first
Create Procedure Gia_Search(
@Shape varchar(64)='',
@color Varchar(64)='',
@purity varchar(64)='',
@polish varchar(64)='',
@cut Varchar(64)='',
@pricemax varchar(50)='',
@pricemin varchar(50)='',
@caratMax varchar(50)='',
@caratmin varchar(50)='',
@symm varchar(64)='',
@fls varchar(64)='',
@userid varchar(64)='',
@PageNumber varchar(50)=0,
@PageSize Varchar(50)=0
)As
Begin
SET NOCOUNT ON;
Declare @Search varchar(max)='', @wherclause varchar(max)=''
if @PageNumber='1'
begin
insert into gia_search_history (user_id,shape_seq,color_seq,purity_Seq,Polish_seq,Cut_Seq,Symm_seq,Fls_Seq,Carats_Max,Carats_Min,Price_max,Price_Min)
values (@userid,@Shape,@color,@purity,@polish,@cut,@symm,@fls,@caratMax,@caratmin,@pricemax,@pricemin)
end
set @Search ='select S.*,SM.Name as shape,CM.Name as Color,PM.Name
as Purity,POM.Name As Polish,CUM.Name as Cut,SYM.Name As Symm,Fm.Name as FLS
from stock as S Inner join SHAPE_MAS As SM
on SM.SEQ_NO=S.shape_seq inner join COLOR_MAS As CM on CM.SEQ_NO=S.color_seq
inner join PURITY_MAS As PM on PM.SEQ_NO=S.PURITY_SEQ inner join POLISH_MAS AS
POM on POM.SEQ_NO=S.polish_seq inner join CUT_MAS As CUM on
CUM.SEQ_NO=S.cut_seq inner join FLS_MAS As FM on FM.SEQ_NO=S.FLS_Seq inner join
SYMM_MAS as SYM on SYM.SEQ_NO=S.SYMM_SEQ'
set @wherclause=' where S.STONE_TYPE =1
and(cts BETWEEN '+@caratmin+' and '+@caratMax+') and (Rate BETWEEN '+@pricemin+' and '+@pricemax+')'
if (@Shape!='')
Begin
set @wherclause +=' and S.shape_seq in ('+@Shape+') '
End
if (@color!='')
Begin
set @wherclause += ' and S.color_seq in ('+@color+')'
End
if (@purity!='')
Begin
set @wherclause +=' and S.purity_seq in ('+@purity+')'
end
if (@cut!='')
Begin
set @wherclause +=' and S.cut_seq in ('+@cut+')'
end
if (@symm!='')
Begin
set @wherclause +=' and S.symm_seq in ('+@symm+')'
end
if (@fls!='')
Begin
set @wherclause +=' and S.Fls_Seq in ('+@fls+')'
end
set @wherclause=+' order by S.SEQ_NO Asc
OFFSET '+@PageSize+' * ('+@PageNumber+' - 1) ROWS FETCH
NEXT '+PageSize+' ROWS ONLY'
set @Search+=@wherclause -- Concatenate all Query
exec(@Search) -- also Call exec sp_executesql @Search
End
Comments
Post a Comment