2014-03-05 237 views
1

我的查詢出現了什麼問題我無法弄清楚。where子句中的select語句sql

Select id, name, description, road_st, sub_area, area, website, email, category, 
      working_hrs, inside_building, logo, latitude, longitude, 
      geom.STNumPoints() as vertices, 
      geom.STAsText() as geom,house_no,building,shop 
      from Points 
      where @hr.STIntersects(geog)= 1 
      and deleted=0 
      and (select s.name from Sub_Category s where s.id=category) 
      like '%'[email protected]+'%' 

錯誤:
如果@text='store'

我越來越沒有結果......但有一個名爲「百貨大樓」

查詢中SUb_category表中的一行工作正常,直到

Select id, name, description, road_st, sub_area, area, website, email, category, 
      working_hrs, inside_building, logo, latitude, longitude, 
      geom.STNumPoints() as vertices, 
      geom.STAsText() as geom,house_no,building,shop 
      from Points 
      where @hr.STIntersects(geog)= 1 
      and deleted=0 

它沒有結果,當我添加此行

  and (select s.name from Sub_Category s where s.id=category) 
      like '%'[email protected]+'%' 

這條線怎麼了?

+2

什麼錯誤得到? – NoobEditor

+0

if @ test =「store」 我沒有得到任何結果......但在SUb_category表中有一行名爲「Departmental Store」 – user3382149

+0

可能是因爲你有一個錯字??? ,您的查詢顯示'@ text'和您發佈的錯誤說'@ test' .. :) – NoobEditor

回答

0
SELECT 
      p.id, 
      p.name, 
      s.name as street, 
      sa.name as sub_area, 
      a.name as area, 
      c.name as city, 
      p.website, 
      p.email, 
      pr.name as province, 
      p.description, 
      sc.name as category, 
      u.UserName as AddedBy, 
      u1.UserName as EditedBy, 
      p.date_added, p.date_edited, 
      p.latitude, 
      p.longitude, 
      p.working_hrs, 
      p.inside_building, 
      p.shop as shop, 
      p.geom.STNumPoints() as vertices, p.geom.STAsText() as geom, 
      hn.name as house,(select abc.name from Points abc where abc.id=p.building)as building 
      from Points p inner join Road_Street s on p.road_st = s.id 
      inner join Subarea sa on p.sub_area = sa.id 
      inner join Area a on p.area = a.id 
      inner join City c on a.city = c.id 
      inner join Sub_Category sc on p.category = sc.id 
      inner join aspnet_users u on p.added_by = u.UserId 
      inner join aspnet_users u1 on p.edited_by = u1.UserId 
      inner join Province pr on c.province = pr.id 
      inner join House_Number hn on p.house_no = hn.id 
      where @hr.STIntersects(p.geog)= 1 
      and p.deleted=0 
      and (select stt.name from Sub_Category stt where stt.id=p.category) like '%'[email protected]+'%' 

描述/更正:與查詢 沒有被擰斷,發生由於ambigious列名錯誤....在倒數第二行我加入「P 「。與刪除。它工作正常!

1
Select id, name, description, road_st, sub_area, area, website, email, category, 
      working_hrs, inside_building, logo, latitude, longitude, 
      geom.STNumPoints() as vertices, 
      geom.STAsText() as geom,house_no,building,shop 
      from Points 
      where @hr.STIntersects(geog)= '1' 
      and deleted='0' 
      and (select s.name from Sub_Category s where s.id=category) 
      like '%'[email protected]+'%' 

試試這個

+1

添加一個解釋,說明你在查詢中已經完成了哪些工作,這是前面沒有的好跡象.... :) – NoobEditor

+0

@ user3291757它的工作....刪除是INT類型列和@ hr.STIntersects(geog)als0返回INT – user3382149