WANFANG-SQL过程

--出租房源的搜索内容显示的存储过程
CREATE procedure Pr_ChuzuRoom_Search_Rs
(
@wherestr varchar(300),
@startIndex int,
@endIndex int
)

As
SET NOCOUNT ON
BEGIN

--创建分页临时表
--判断表是不是存在,若存在就清空表,若不存在就建立表
if exists(select * from sysobjects where id=object_id('indextable1'))
truncate table indextable1
else
create table indextable1(id int identity(1,1),nid int)

EXEC('insert into indextable1(nid) select roomid from room where '+@wherestr)

select O.*,A.areaname,S.spacename,B.buildingname from room O left join area A on(O.areaid=A.areaid) left join space S on(S.spaceid=O.spaceid) left join building B on(O.zoneid=B.buildingid),indextable1 t where O.sellorlease=1 and O.roomid=t.nid and t.id between @startIndex and @endIndex order by t.id
END 
SET NOCOUNT OFF

GO
 
  
  
  
  

-- 得到小区排行的存储过程,小区按点击量排行
--
名称:Pr_Uzonename 参数:小区的id号
--
状态:未用到
Alter   procedure  Pr_Uzonepaihang
(
@uzoneid   int
)
AS
begin
declare   @clickcount   int
set   @clickcount = ( select  clickcount  from  building  where  buildingid = @uzoneid  )
declare   @indextable   table (nid  int )
insert   into   @indextable   select   count ( * from  building  where  clickcount > @clickcount
select  nid + 1   from   @indextable
end
GO


-- 得到小区统计的存储过程,小区按点击量排行 和人气 和业主数
--
名称:Pr_Uzonename 参数:小区的id号
--
状态:用到
Alter   procedure  Pr_Uzonepaihang
(
@uzoneid   int
)
AS
begin

-- 人气
declare   @clickcount   int
set   @clickcount = ( select  clickcount  from  building  where  buildingid = @uzoneid  )
-- 排行
declare   @num   int
set   @num = ( select   count ( * from  building  where  clickcount > @clickcount )
-- 业主数
declare   @usernum   int
declare   @temptable   table (a  int )
insert   into   @temptable   select   DISTINCT  userid  from  room  where  zoneid = @uzoneid
set   @usernum = ( select   count ( * from   @temptable  )
-- 把以上参数合并到表
declare   @indextable   table (paihang  int ,clickcount  int ,usernum  int )
insert   into   @indextable   VALUES ( @num + 1 , @clickcount , @usernum )
select   *   from   @indextable
end
GO

-- 得到小区的基本信息的存储过程
--
名称Pr_GetUz_BaseInfo 参数:小区的id号
--
状态用到
create   procedure  Pr_GetUz_BaseInfo
@uzoneid   int
AS
select  B. * ,S.spacename,A.areaname  from  building B  LEFT   JOIN  area A  ON (B.areaid = A.areaid)  LEFT   JOIN   space  S  ON

(S.spaceid
= b.spaceid)  where  B.buildingid = @uzoneid   AND  B.isbuilding = 1
GO


-- 得到指定小区的周边小区的小区或者新楼盘的信息
--
名称
--
用到
create   procedure  Pr_GetUz_Nearbuilding
(
@uzoneid   int , @type   int , @count1   int
)
AS
begin
declare   @spaceid   int
set   @spaceid = ( select  spaceid  from  building  where  buildingid = @uzoneid )
ExEc  ( ' select top ' +   @count1 + '  * from building where spaceid= ' + @spaceid + '  AND isbuilding= ' + @type )
end

-- 第二个版本
create   procedure  Pr_GetUz_Nearbuilding
(
@uzoneid   int , @type   int , @count1   int
)
AS
begin
declare   @spaceid   int
set   Rowcount   @count1   
set   @spaceid = ( select  spaceid  from  building  where  buildingid = @uzoneid )
select   *   from  building  where  spaceid = @spaceid   AND  isbuilding = @type
end

-- 视图的V_zonepinglun_user

SET  QUOTED_IDENTIFIER  ON  
GO
SET  ANSI_NULLS  ON  
GO


ALTER     VIEW  dbo.V_zonepinglun_user
AS
SELECT  dbo.users.username, dbo.usedzoneremark. *
FROM  dbo.usedzoneremark  LEft   JOIN
      dbo.users 
ON  dbo.usedzoneremark.userid  =  dbo.users.userid


GO
SET  QUOTED_IDENTIFIER  OFF  
GO
SET  ANSI_NULLS  ON  
GO


-- 插入一条小区的评论记录
create   procedure  Pr_Insert_aremark
(
@uzoneid   int , @compare   tinyint , @ismarkup   tinyint , @factprice   money , @userid   int , @content   text
)
AS
begin
INSERT   INTO  usedzoneremark(buildingid,compare,factprice,ismarkup,content,userid) VALUES

(
@uzoneid , @compare , @factprice , @ismarkup , @content , @userid )
end


-- 得到指定小区的出售房源和出租房源
--
0:售 1:租,2:出售租均可
--
用到
ALTER    procedure  Pr_GetUz_Rooms
(
@uzoneid   int , @type   int , @count1   int
)
AS
begin
if ( @count1 = 0 )
ExEc  ( ' select * from room where zoneid= ' + @uzoneid + '  AND sellorlease= ' + @type )
else
ExEc  ( ' select top  ' +   @count1 + '  * from room where zoneid= ' + @uzoneid + '  AND sellorlease= ' + @type )
end


SET  QUOTED_IDENTIFIER  ON  
GO
SET  ANSI_NULLS  ON  
GO


-- 得到指定小区的出售房源和出租房源
--
0:售 1:租,2:出售租均可
--
用到
ALTER     procedure  Pr_GetUz_Rooms
(
@uzoneid   int , @type   int , @count1   int
)
AS
begin
if ( @count1 = 0 )
    
if ( @type = 3 )
        
ExEc  ( ' select * from room where zoneid= ' + @uzoneid )
    
else
        
ExEc  ( ' select * from room where zoneid= ' + @uzoneid + '  AND sellorlease= ' + @type )
else
ExEc  ( ' select top  ' +   @count1 + '  * from room where zoneid= ' + @uzoneid + '  AND sellorlease= ' + @type )
end


GO
SET  QUOTED_IDENTIFIER  OFF  
GO
SET  ANSI_NULLS  ON  
GO


-- 得到周边中介
CREATE   procedure  Pr_Uz_GetZhongJie
(
@uzoneid    int ,
@startIndex   int ,
@endIndex   int ,
@docount   tinyint )
AS
BEGIN  
declare   @spaceid   int
set   @spaceid   = ( select  spaceid  from  building  where  buildingid = @uzoneid   and  isbuilding = 1 )
-- 当@docount>=1,就返回@docount指定的条说记录,否则分页
if ( @docount >= 1 )
    
EXEc ( ' select top  ' + @docount + '  * from zhongjie where spaceid= ' + @spaceid )
else
    
begin
    
declare   @indextable   table (id  int   identity ( 1 , 1 ),nid  int )
    
set   rowcount   @endIndex
    
insert   into   @indextable (nid)  select  zhongjieid  from  zhongjie   where  spaceid = @spaceid
    
select   *   from  zhongjie Z, @indextable  T  where  Z.zhongjieid = T.nid  and  T.id  between   @startIndex   and   @endIndex  

order   by  T.id
    
end
END

 
  
  
  
  

-- 得到小区排行的存储过程,小区按点击量排行
--
名称:Pr_Uzonename 参数:小区的id号
--
状态:未用到
Alter   procedure  Pr_Uzonepaihang
(
@uzoneid   int
)
AS
begin
declare   @clickcount   int
set   @clickcount = ( select  clickcount  from  building  where  buildingid = @uzoneid  )
declare   @indextable   table (nid  int )
insert   into   @indextable   select   count ( * from  building  where  clickcount > @clickcount
select  nid + 1   from   @indextable
end
GO


-- 得到小区统计的存储过程,小区按点击量排行 和人气 和业主数
--
名称:Pr_Uzonename 参数:小区的id号
--
状态:用到
Alter   procedure  Pr_Uzonepaihang
(
@uzoneid   int
)
AS
begin

-- 人气
declare   @clickcount   int
set   @clickcount = ( select  clickcount  from  building  where  buildingid = @uzoneid  )
-- 排行
declare   @num   int
set   @num = ( select   count ( * from  building  where  clickcount > @clickcount )
-- 业主数
declare   @usernum   int
declare   @temptable   table (a  int )
insert   into   @temptable   select   DISTINCT  userid  from  room  where  zoneid = @uzoneid
set   @usernum = ( select   count ( * from   @temptable  )
-- 把以上参数合并到表
declare   @indextable   table (paihang  int ,clickcount  int ,usernum  int )
insert   into   @indextable   VALUES ( @num + 1 , @clickcount , @usernum )
select   *   from   @indextable
end
GO

-- 得到小区的基本信息的存储过程
--
名称Pr_GetUz_BaseInfo 参数:小区的id号
--
状态用到
create   procedure  Pr_GetUz_BaseInfo
@uzoneid   int
AS
select  B. * ,S.spacename,A.areaname  from  building B  LEFT   JOIN  area A  ON (B.areaid = A.areaid)  LEFT   JOIN   space  S  ON

(S.spaceid
= b.spaceid)  where  B.buildingid = @uzoneid   AND  B.isbuilding = 1
GO


-- 得到指定小区的周边小区的小区或者新楼盘的信息
--
名称
--
用到
create   procedure  Pr_GetUz_Nearbuilding
(
@uzoneid   int , @type   int , @count1   int
)
AS
begin
declare   @spaceid   int
set   @spaceid = ( select  spaceid  from  building  where  buildingid = @uzoneid )
ExEc  ( ' select top ' +   @count1 + '  * from building where spaceid= ' + @spaceid + '  AND isbuilding= ' + @type )
end

-- 第二个版本
create   procedure  Pr_GetUz_Nearbuilding
(
@uzoneid   int , @type   int , @count1   int
)
AS
begin
declare   @spaceid   int
set   Rowcount   @count1   
set   @spaceid = ( select  spaceid  from  building  where  buildingid = @uzoneid )
select   *   from  building  where  spaceid = @spaceid   AND  isbuilding = @type
end

-- 视图的V_zonepinglun_user

SET  QUOTED_IDENTIFIER  ON  
GO
SET  ANSI_NULLS  ON  
GO


ALTER     VIEW  dbo.V_zonepinglun_user
AS
SELECT  dbo.users.username, dbo.usedzoneremark. *
FROM  dbo.usedzoneremark  LEft   JOIN
      dbo.users 
ON  dbo.usedzoneremark.userid  =  dbo.users.userid


GO
SET  QUOTED_IDENTIFIER  OFF  
GO
SET  ANSI_NULLS  ON  
GO


-- 插入一条小区的评论记录
create   procedure  Pr_Insert_aremark
(
@uzoneid   int , @compare   tinyint , @ismarkup   tinyint , @factprice   money , @userid   int , @content   text
)
AS
begin
INSERT   INTO  usedzoneremark(buildingid,compare,factprice,ismarkup,content,userid) VALUES

(
@uzoneid , @compare , @factprice , @ismarkup , @content , @userid )
end


-- 得到指定小区的出售房源和出租房源
--
0:售 1:租,2:出售租均可
--
用到
ALTER    procedure  Pr_GetUz_Rooms
(
@uzoneid   int , @type   int , @count1   int
)
AS
begin
if ( @count1 = 0 )
ExEc  ( ' select * from room where zoneid= ' + @uzoneid + '  AND sellorlease= ' + @type )
else
ExEc  ( ' select top  ' +   @count1 + '  * from room where zoneid= ' + @uzoneid + '  AND sellorlease= ' + @type )
end


SET  QUOTED_IDENTIFIER  ON  
GO
SET  ANSI_NULLS  ON  
GO


-- 得到指定小区的出售房源和出租房源
--
0:售 1:租,2:出售租均可
--
用到
ALTER     procedure  Pr_GetUz_Rooms
(
@uzoneid   int , @type   int , @count1   int
)
AS
begin
if ( @count1 = 0 )
    
if ( @type = 3 )
        
ExEc  ( ' select * from room where zoneid= ' + @uzoneid )
    
else
        
ExEc  ( ' select * from room where zoneid= ' + @uzoneid + '  AND sellorlease= ' + @type )
else
ExEc  ( ' select top  ' +   @count1 + '  * from room where zoneid= ' + @uzoneid + '  AND sellorlease= ' + @type )
end


GO
SET  QUOTED_IDENTIFIER  OFF  
GO
SET  ANSI_NULLS  ON  
GO


-- 得到周边中介
CREATE   procedure  Pr_Uz_GetZhongJie
(
@uzoneid    int ,
@startIndex   int ,
@endIndex   int ,
@docount   tinyint )
AS
BEGIN  
declare   @spaceid   int
set   @spaceid   = ( select  spaceid  from  building  where  buildingid = @uzoneid   and  isbuilding = 1 )
-- 当@docount>=1,就返回@docount指定的条说记录,否则分页
if ( @docount >= 1 )
    
EXEc ( ' select top  ' + @docount + '  * from zhongjie where spaceid= ' + @spaceid )
else
    
begin
    
declare   @indextable   table (id  int   identity ( 1 , 1 ),nid  int )
    
set   rowcount   @endIndex
    
insert   into   @indextable (nid)  select  zhongjieid  from  zhongjie   where  spaceid = @spaceid
    
select   *   from  zhongjie Z, @indextable  T  where  Z.zhongjieid = T.nid  and  T.id  between   @startIndex   and   @endIndex  

order   by  T.id
    
end
END

CREATE procedure Pr_Uz_Guapailiang_Paihang
(
@rowcount  Int
)
as
begin
set rowcount @rowcount
select B.buildingname,B.avgprice,B.buildingid,R.roomnum,A.areaname from building B  left join V_roomnum R on (B.buildingid=R.zoneid) left join area A on (A.areaid=B.areaid) Where B.isbuilding=1 order by R.roomnum DESC
end
GO
CREATE procedure Pr_Uz_Search_Rs 
(
@wherestr varchar(300),
@startIndex int,
@endIndex int
)

As
SET NOCOUNT ON
BEGIN

--创建分页临时表
--判断表是不是存在,若存在就清空表,若不存在就建立表
if exists(select * from sysobjects where id=object_id('indextable'))
truncate table indextable
else
create table indextable(id int identity(1,1),nid int)

EXEC('insert into indextable(nid) select buildingid from building where '+@wherestr)

select O.* from building O,indextable t where O.isbuilding=1 and O.buildingid=t.nid and t.id between @startIndex and @endIndex order by t.id
END 
SET NOCOUNT OFF
GO
 
 
 
 
CREATE VIEW dbo.V_roomnum
AS
SELECT TOP 100 PERCENT zoneid AS zoneid, COUNT(roomid) AS roomnum
FROM a0522144228.room
GROUP BY zoneid
ORDER BY roomnum DESC
CREATE PROCEDURE Pr_InsertAZhongjie
(
 @areaid int,
           @spaceid int,
 @company varchar(100),
 @address varchar(100),
 @linkman varchar(100),
 @phone varchar(100),
 @chuanzhen varchar(100),
 @jianjie text,
 @gonggao text
)
AS
 insert into zhongjie(areaid,spaceid,company,address,linkman,phone,chuanzhen,jianjie,gonggao)VALUES(@areaid,@spaceid,@company,@address,@linkman,@phone,@chuanzhen,@jianjie,@gonggao)
GO

你可能感兴趣的:(JOIN,object,table,search,存储,insert)