문제

SELECT surplusland_list.*,site_file_sets.*,demandstar.identifier, demandstar.date_due
FROM surplusland_list,site_file_sets,demandstar
WHERE surplusland_list.its_number != 'NULL' AND 
      surplusland_list.its_number = demandstar.identifier AND
      site_file_sts.name LIKE %{demandstar.identifier}%
ORDER BY surplusland_list.county ASC, surplusland_list.assoc_property ASC, surplusland_list.id ASC

How can I correct this statement? I have an error at the %{demandstar.identifier}%. I have tried many different versions of this statment and cant seem to get it to work. Thanks in advance!

도움이 되었습니까?

해결책 2

Your statement has multiple problems. First, you should learn and use proper join syntax and realize that table aliases will simplify the query. That will show that you have no join condition for site_file_sets, which this is showing as a cross join.

SELECT sl.*, sfs.*, ds.identifier, ds.date_due
FROM surplusland_list sl join
     demandstart ds
     on sl.its_number = ds.identifier cross join
     site_file_sets sfs
WHERE sl.its_number != 'NULL' AND 
      sfs.name LIKE %{demandstar.identifier}%
ORDER BY sl.county ASC, sl.assoc_property ASC, sl.id ASC;

The next two problems are the lack of single quote around the like pattern, and the != NULL. The != NULL will always return NULL which is treated as false. This is the improved version:

SELECT sl.*, sfs.*, ds.identifier, ds.date_due
FROM surplusland_list sl join
     demandstart ds
     on sl.its_number = ds.identifier cross join
     site_file_sets sfs
WHERE sl.its_number is not 'NULL' AND 
      sfs.name LIKE '%{demandstar.identifier}%'
ORDER BY sl.county ASC, sl.assoc_property ASC, sl.id ASC;

However, this will not do what you want until you replace the cross join with an appropriate join and on clause.

다른 팁

The argument to LIKE is a string, and should be properly quoted.

Try LIKE '%{demandstar.identifier}%'

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top