日期:2014-05-17 浏览次数:20499 次
ALTER PROCEDURE [dbo].[Tb_AdvancedSearch]
(
@fld_GoodsClassId int,
@fld_StartLevel nvarchar(50),
@fld_DistrictId int,
@fld_CreatedTime datetime
)
AS
begin
declare @sql nvarchar(1000) --生成的sql语句
if @fld_DistrictId = 0
begin
set @sql = 'select b.*,
c.fld_UserName as fld_UserName,
d.fld_DistrictName as fld_DistrictName,
e.fld_GoodsClassName as fld_GoodsClassName,
*
FROM Tb_Goods as b inner join Tb_User as c on b.fld_UserId = c.fld_UserId
inner join Tb_District as d on b.fld_DistrictId = d.fld_DistrictId
inner join Tb_GoodsClass as e on b.fld_GoodsClassId = e.fld_GoodsClassId
WHERE b.fld_GoodsClassId = ''' + cast(@fld_GoodsClassId as varchar(10)) + ''' and fld_StartLevel = ''' + @fld_StartLevel + ''' and fld_CreatedTime >= ''' + cast(@fld_CreatedTime as varchar)
exec sp_executesql @sql
end
else
begin
set @sql = 'select b.*,
c.fld_UserName as fld_UserName,
d.fld_DistrictName as fld_DistrictName,
e.fld_GoodsClassName as fld_GoodsClassName,
*
FROM Tb_Goods as b inner join Tb_User as c on b.fld_UserId = c.fld_UserId
inner join Tb_District as d on b.fld_DistrictId = d.fld_DistrictId
inner join Tb_GoodsClass as e on b.fld_GoodsClassId = e.fld_GoodsClassId
WHERE b.fld_GoodsClassId = ''' + cast(@fld_GoodsClassId as varchar(10)) + ''' and fld_StartLevel = ''' + @fld_StartLevel + ''' and fld_CreatedTime >= ''' +cast(@fld_CreatedTime as varchar) + ''' and fld_DistrictId = ''' + cast(@fld_DistrictId as varchar)
exec sp_executesql @sql
end
end