2014-03-05 43 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