- 论坛徽章:
- 0
|
查询出来的字段不是同一个表中的字段。我没有写过存储过程,瞎写了一个,请大虾帮我改一下。
set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
go
ALTER PROCEDURE [dbo].[sp_Member_GetMemberProduct]
@infotype int, --信息类型:1:供应 2:求购,不能为空
@protypechilid int, --子类型编号,不能为空
@comproid int, --省份id
@comcityid int, --市id
@keyWords varchar(500), --搜索关键字
@userlevel int , --查看鼎诚商会员
@onlineUser int, --仅查看在线会员
@Area int, --按省份筛选
@pagesize int, --显示的数据条数
@pageindex int --当前页面
AS
declare @strSql varchar(5000) --输入的sql
declare @strOrderby varchar(50) --order by
set @strSql=\' select mp.title,mp.pubtime,mp.descript,udi.comname,ui.uid,ui.uname,(select count(*) from certificate where uid=ui.uid and certypename=\'\'xx\'\') as a,(select count(*) from certificate where uid=ui.uid and certypename=\'yy\'\') as b,ui.ulevel,mp.mpnum,mi.limage,p.ProName,c.cityname from userinfo ui,userdinfo udi,memberproduct mp,mimages mi,provinceList p,citylist c where ui.uid = mp.uid and ui.uid = udi.uid and mp.mpnum = mi.mpnum and mp.infostate = 2 and mp.isshow = 1 and udi.ComProID=p.ComProID and udi.comcityid= c.comcityid and ui.ulevel < 6 \'
set @strOrderby=\'order by ui.ULevel DESC, mp.PubTime DESC\'
if(@infotype <> \'\')--关键字不为空时
begin
set @strSql = @strSql + \' and mp.infotype = \' + @infotype
END
if(@protypechilid <> \'\')--关键字不为空时
begin
set @strSql = @strSql + \' and mp.protypechilid = \' + @protypechilid
END
if(@comproid <> \'\')--关键字不为空时
begin
set @strSql = @strSql + \' and udi.comproid = \' + @comproid
END
if(@comcityid <> \'\')--关键字不为空时
begin
set @strSql = @strSql + \' and udi.comcityid = \' + @comcityid
END
if(@userlevel <> \'\')--关键字不为空时
begin
set @strSql = @strSql + \' and ui.ulevel = \' + @userlevel
END
--if(@onlineUser <> \'\')--关键字不为空时
--begin
--@strSql = @strSql + \'\'
--END
if(@Area <> \'\')--关键字不为空时
begin
set @strSql = @strSql + \' and udi.ComProID = \' + @Area
END
if(@keyWords <> \'\')--关键字不为空时
begin
set @strSql = @strSql + \' and ( mp.title like \'\'%\' + @keyWords + \'%\'\'
or mp.Descript like \'\'%\' + @keyWords + \'%\'\'
or mp.ProName like \'\'%\'+@keyWords+\'%\'\'
or mp.ProArea like \'\'%\'+@keyWords+\'%\'\'
or mp.ProModel like \'\'%\'+@keyWords+\'%\'\'
or udi.ComName like \'\'%\'+@keyWords+\'%\'\'
or udi.Office like \'\'%\'+@keyWords+\'%\'\'
or udi.ComAddress like \'\'%\'+@keyWords+\'%\'\'
or udi.RegAddress like \'\'%\'+@keyWords+\'%\'\'
or udi.ComIntr like \'\'%\'+@keyWords+\'%\'\' ) \'
END
set @strSql = @strSql + @strOrderby |
|