create proc pr_test
@IN_STORE_CODE varchar(11),
@in_date_start varchar(8),
@in_date_end varchar(8),
@state_flag char(1),
@WH_CODE varchar(3),
@RECIPT_NO char(11),
@SUP_NAME varchar(60),
@MATERIAL_CODE varchar(12),
@M_NAME varchar(30)
as
declare @sql varchar(1000)
declare @sqlwhere varchar(1000)
set @sql='SELECT distinct b.IN_STORE_CODE,f.ZB_NAME,'
set @sql=@sql+'IN_DATE=left(b.in_date,4)+''-''+substring(b.in_date,5,2)+''-''+right(b.in_date,2),'
set @sql=@sql+'b.RECIPT_NO,b.CG_ORDER_MANAGER_NUM,g.wh_name,'
set @sql=@sql+'in_kind = case in_kind when ''1'' then ''蓝'' else ''红'' end,'
set @sql=@sql+'h.[NAME],c.MATERIAL_CODE,d.M_NAME,d.MODEL,d.UNIT,c.PRAV_IN_QUAN,c.PRICE_PRV,c.MONEY_PR,e.SUP_NAME,b.STATE_FLAG,'
set @sql=@sql+'b.TRAN_TYPE,b.TRAN_COMP_CODE,BUY_PERSON_CODE=i.fullname,b.REMARK '
set @sql=@sql+'FROM GS_RECIPT_MAIN a RIGHT JOIN GF_IN_MAIN b ON a.RECIPT_NO = b.RECIPT_NO '
set @sql=@sql+'left outer join gs_sy_jyxz f ON b.IN_TYPE=F.ZB_CODE '
set @sql=@sql+'left outer join gf_warehouse g ON b.WH_CODE=g.WH_CODE '
set @sql=@sql+'left outer join (select code,[name] from BO_SY_CODE WHERE CODE_TYPE=''21'') h ON b.DEPT_CODE=h.code '
set @sql=@sql+'left outer join users i ON b.BUY_PERSON_CODE=i.userid '
set @sql=@sql+'INNER JOIN GF_IN_SUB c ON b.IN_STORE_CODE = c.IN_STORE_CODE '
set @sql=@sql+'left outer join GS_MATE d ON c.MATERIAL_CODE = d.MATERIAL_CODE '
set @sql=@sql+'left outer join GS_SUPPLIER e ON e.SUP_CODE=b.SUP_CODE '
if @in_store_code<>''
begin
set @sqlwhere='where b.in_store_code='+''''+@in_store_code+''''
end
if @in_date_start<>''
begin
if @sqlwhere<>''
set @sqlwhere=@sqlwhere+' and in_date>='+''''+@in_date_start+''''
else
set @sqlwhere='where in_date>='+''''+@in_date_start+''''
end
if @in_date_end<>''
begin
if @sqlwhere<>''
set @sqlwhere=@sqlwhere+' and in_date<='+''''+@in_date_end+''''
else
set @sqlwhere='where in_date<='+''''+@in_date_end+''''
end
if @state_flag<>''
begin
if @sqlwhere<>''
set @sqlwhere=@sqlwhere+' and state_flag='+''''+@state_flag+''''
else
set @sqlwhere='where state_flag='+''''+@state_flag+''''
end
if @WH_CODE<>''
begin
if @sqlwhere<>''
set @sqlwhere=@sqlwhere+' and b.WH_CODE='+''''+@WH_CODE+''''
else
set @sqlwhere='where b.WH_CODE='+''''+@WH_CODE+''''
end
if @RECIPT_NO<>''
begin
if @sqlwhere<>''
set @sqlwhere=@sqlwhere+' and b.RECIPT_NO='+''''+@RECIPT_NO+''''
else
set @sqlwhere='where b.RECIPT_NO='+''''+@RECIPT_NO+''''
end
if @SUP_NAME<>''
begin
if @sqlwhere<>''
set @sqlwhere=@sqlwhere+' and e.SUP_NAME like ''%'+@SUP_NAME+'%'''
else
set @sqlwhere='where e.SUP_NAME like ''%'+@SUP_NAME+'%'''
end
if @MATERIAL_CODE<>''
begin
if @sqlwhere<>''
set @sqlwhere=@sqlwhere+' and c.MATERIAL_CODE='+''''+@MATERIAL_CODE+''''
else
set @sqlwhere='where c.MATERIAL_CODE='+''''+@MATERIAL_CODE+''''
end
if @M_NAME<>''
begin
if @sqlwhere<>''
set @sqlwhere=@sqlwhere+' and d.M_NAME like ''%'+@M_NAME+'%'''
else
set @sqlwhere='where d.M_NAME like ''%'+@M_NAME+'%'''
end
set @sql=@sql+@sqlwhere
exec (@sql)
@IN_STORE_CODE varchar(11),
@in_date_start varchar(8),
@in_date_end varchar(8),
@state_flag char(1),
@WH_CODE varchar(3),
@RECIPT_NO char(11),
@SUP_NAME varchar(60),
@MATERIAL_CODE varchar(12),
@M_NAME varchar(30)
as
declare @sql varchar(1000)
declare @sqlwhere varchar(1000)
set @sql='SELECT distinct b.IN_STORE_CODE,f.ZB_NAME,'
set @sql=@sql+'IN_DATE=left(b.in_date,4)+''-''+substring(b.in_date,5,2)+''-''+right(b.in_date,2),'
set @sql=@sql+'b.RECIPT_NO,b.CG_ORDER_MANAGER_NUM,g.wh_name,'
set @sql=@sql+'in_kind = case in_kind when ''1'' then ''蓝'' else ''红'' end,'
set @sql=@sql+'h.[NAME],c.MATERIAL_CODE,d.M_NAME,d.MODEL,d.UNIT,c.PRAV_IN_QUAN,c.PRICE_PRV,c.MONEY_PR,e.SUP_NAME,b.STATE_FLAG,'
set @sql=@sql+'b.TRAN_TYPE,b.TRAN_COMP_CODE,BUY_PERSON_CODE=i.fullname,b.REMARK '
set @sql=@sql+'FROM GS_RECIPT_MAIN a RIGHT JOIN GF_IN_MAIN b ON a.RECIPT_NO = b.RECIPT_NO '
set @sql=@sql+'left outer join gs_sy_jyxz f ON b.IN_TYPE=F.ZB_CODE '
set @sql=@sql+'left outer join gf_warehouse g ON b.WH_CODE=g.WH_CODE '
set @sql=@sql+'left outer join (select code,[name] from BO_SY_CODE WHERE CODE_TYPE=''21'') h ON b.DEPT_CODE=h.code '
set @sql=@sql+'left outer join users i ON b.BUY_PERSON_CODE=i.userid '
set @sql=@sql+'INNER JOIN GF_IN_SUB c ON b.IN_STORE_CODE = c.IN_STORE_CODE '
set @sql=@sql+'left outer join GS_MATE d ON c.MATERIAL_CODE = d.MATERIAL_CODE '
set @sql=@sql+'left outer join GS_SUPPLIER e ON e.SUP_CODE=b.SUP_CODE '
if @in_store_code<>''
begin
set @sqlwhere='where b.in_store_code='+''''+@in_store_code+''''
end
if @in_date_start<>''
begin
if @sqlwhere<>''
set @sqlwhere=@sqlwhere+' and in_date>='+''''+@in_date_start+''''
else
set @sqlwhere='where in_date>='+''''+@in_date_start+''''
end
if @in_date_end<>''
begin
if @sqlwhere<>''
set @sqlwhere=@sqlwhere+' and in_date<='+''''+@in_date_end+''''
else
set @sqlwhere='where in_date<='+''''+@in_date_end+''''
end
if @state_flag<>''
begin
if @sqlwhere<>''
set @sqlwhere=@sqlwhere+' and state_flag='+''''+@state_flag+''''
else
set @sqlwhere='where state_flag='+''''+@state_flag+''''
end
if @WH_CODE<>''
begin
if @sqlwhere<>''
set @sqlwhere=@sqlwhere+' and b.WH_CODE='+''''+@WH_CODE+''''
else
set @sqlwhere='where b.WH_CODE='+''''+@WH_CODE+''''
end
if @RECIPT_NO<>''
begin
if @sqlwhere<>''
set @sqlwhere=@sqlwhere+' and b.RECIPT_NO='+''''+@RECIPT_NO+''''
else
set @sqlwhere='where b.RECIPT_NO='+''''+@RECIPT_NO+''''
end
if @SUP_NAME<>''
begin
if @sqlwhere<>''
set @sqlwhere=@sqlwhere+' and e.SUP_NAME like ''%'+@SUP_NAME+'%'''
else
set @sqlwhere='where e.SUP_NAME like ''%'+@SUP_NAME+'%'''
end
if @MATERIAL_CODE<>''
begin
if @sqlwhere<>''
set @sqlwhere=@sqlwhere+' and c.MATERIAL_CODE='+''''+@MATERIAL_CODE+''''
else
set @sqlwhere='where c.MATERIAL_CODE='+''''+@MATERIAL_CODE+''''
end
if @M_NAME<>''
begin
if @sqlwhere<>''
set @sqlwhere=@sqlwhere+' and d.M_NAME like ''%'+@M_NAME+'%'''
else
set @sqlwhere='where d.M_NAME like ''%'+@M_NAME+'%'''
end
set @sql=@sql+@sqlwhere
exec (@sql)