当前位置: 代码迷 >> Sql Server >> sql 查询,该怎么处理
  详细解决方案

sql 查询,该怎么处理

热度:74   发布时间:2016-04-27 19:40:12.0
sql 查询
sql语句:
set   @sql= 'select   distinct   p.Name   as   姓名   , ' '中国 ' '   as     country   , ' '上海 ' '   as   house,p.CardNumber   as   身份证,t4.allcount   as   次数   from   Peoples   p   inner   join  
#table4   t4   on   t4.PeopleID   =   p.PeopleID   inner   join   Deals   d   on   d.BuyID   =   p.PeopleID   INNER   JOIN
dbo.Houses   AS   h   ON   d.HouseID   =   h.HouseID   left   join   HouseType   ht   on   ht.TypeID   =   h.HouseTypeID   where   '
set   @sql   =   @sql   +   '   d.CheckTime> = ' ' '+cast(@startdate   as   nvarchar(10))+ ' ' '       and '
set   @sql   =   @sql   +   '   d.CheckTime <= ' ' '+cast(@enddate   as   nvarchar(10))+ ' ' '       and '

if   @Name   <>   ' '
        set   @[email protected]+ '   p.Name   like   ' ' '[email protected]+ '% ' '       and   '
if   @id   <>   ' '
        set   @[email protected]+ '   p.CardNumber   like   ' '% '[email protected]+ '% ' '       and   '
if     @cishu   <>   ' '
if   @cishu   =   '首次交易者 '
      set   @[email protected]+ '   t4.allcount   =   1       and '
if   @cishu   =   '2次交易者 '
set   @[email protected]+ '   t4.allcount=   2       and '
if   @cishu   =   '3-5次交易者 '
set   @[email protected]+ '   t4.allcount   in   (3,4,5)       and '
if   @cishu   =   '5-10次交易者 '
set   @[email protected]+ '   t4.allcount   in   (6,7,8,9,10)       and '
if   @cishu   =   '10次以上交易者 '
set   @[email protected]+ '   t4.allcount   >   10       and '
if     @qu   <>   ' '
set   @[email protected]+ '   h.qu= ' ' '[email protected]+ ' ' '       and '

if     @leixing   <>   ' '
begin
if   @leixing   =   '公寓 '
set   @[email protected]+ '   ht.HouseTypeName   in   ( ' '新工房 ' ', ' '新式公寓 ' ')       and   '
if   @leixing   =   '别墅 '
set   @[email protected]+ '   ht.HouseTypeName   =   ' '公园别墅 ' '   or   h.XiangMu   like   ' '%别墅% ' '   or   h.Shi   like   ' '%全幢% ' '   or   h.Shi   like   ' '%层% ' '   or   h.Hao   like   ' '%全幢% ' '     and   '
if   @leixing   =   '联排 '
set   @[email protected]+ '   ht.HouseTypeName   =   ' '联体 ' '       and   '
if   @leixing   =   '办公 '
set   @[email protected]+ '   ht.HouseTypeName   =   ' '办公楼 ' '       and   '
if   @leixing   =   '商铺 '
  相关解决方案