为什么这个存储确实会返回结果

时间:2016-10-12 15:19:06

标签: mysql sql

我已经创建了这个存储的函数来构建高级搜索过程但是我注意到它没有返回任何结果,虽然我尝试使用代码而不使用存储任何正确的返回结果

我认为参数SearchWord

有问题
DELIMITER //
CREATE PROCEDURE AdvancedSearch(IN SearchWord VARCHAR(255))
  BEGIN
    SELECT * FROM (

                    SELECT CustomerId AS id,CustomerCompany  AS name ,null AS descrip,null AS FileName
                    FROM tbcustomers
                      LEFT JOIN tbfiles ON tbcustomers.CustomerId  = tbfiles.CatId AND tbfiles.ModuleName = "customers"
                    WHERE tbcustomers.CustomerCompany LIKE  CONCAT('%', @SearchWord , '%')

                    UNION
                    SELECT DeviceId AS id,DeviceName AS name,DeviceDesc AS descrip,FileName
                    FROM tbdevices
                      LEFT JOIN tbfiles ON tbdevices.DeviceId  = tbfiles.CatId AND tbfiles.ModuleName = "devices"
                    WHERE tbdevices.DeviceName  LIKE  CONCAT('%', @SearchWord , '%')
                          OR tbdevices.DeviceDesc  LIKE CONCAT('%', @SearchWord , '%')
                          OR tbdevices.DeviceProperties  LIKE CONCAT('%', @SearchWord , '%')

                    UNION
                    SELECT HostingId AS id,HostingName  AS name,HostingType AS descrip,FileName
                    FROM tbhosting
                      LEFT JOIN tbfiles ON tbhosting.HostingId  = tbfiles.CatId AND tbfiles.ModuleName = "hosting"
                    WHERE tbhosting.HostingName  LIKE CONCAT('%', @SearchWord , '%')
                          OR    tbhosting.HostingType  LIKE CONCAT('%', @SearchWord , '%')
                          OR   tbhosting.HostingSpace  LIKE CONCAT('%', @SearchWord , '%')
                          OR   tbhosting.HostingRam  LIKE CONCAT('%', @SearchWord , '%')
                          OR  tbhosting.HostingUsage  LIKE CONCAT('%', @SearchWord , '%')
                          OR tbhosting.HostingUsagebases  LIKE CONCAT('%', @SearchWord , '%')

                    UNION
                    SELECT PageId AS id,PageTitle  AS name,PageDesc AS descrip,FileName
                    FROM tbpages
                      LEFT JOIN tbfiles ON tbpages.PageId  = tbfiles.CatId AND tbfiles.ModuleName = "pages"
                    WHERE tbpages.PageTitle  LIKE CONCAT('%', @SearchWord , '%')
                          OR    tbpages.PageDesc  LIKE CONCAT('%', @SearchWord , '%')
                          OR   tbpages.PageSubject  LIKE CONCAT('%', @SearchWord , '%')


                    UNION
                    SELECT ProductId AS id,ProductName  AS name,ProductDesc AS descrip,FileName
                    FROM tbproducts
                      LEFT JOIN tbfiles ON tbproducts.ProductId  = tbfiles.CatId AND tbfiles.ModuleName = "products"
                    WHERE tbproducts.ProductName  LIKE CONCAT('%', @SearchWord , '%')
                          OR    tbproducts.ProductTitle  LIKE CONCAT('%', @SearchWord , '%')
                          OR   tbproducts.ProductDesc  LIKE CONCAT('%', @SearchWord , '%')
                          OR   tbproducts.ProductProperties  LIKE CONCAT('%', @SearchWord , '%')
                          OR   tbproducts.ProductPrice  LIKE CONCAT('%', @SearchWord , '%')
                          OR   tbproducts.ProductNumVersion  LIKE CONCAT('%', @SearchWord , '%')

                    UNION
                    SELECT ProjectId AS id,ProjectName  AS name,ProjectDesc AS descrip,FileName
                    FROM tbprojects
                      LEFT JOIN tbfiles ON tbprojects.ProjectId  = tbfiles.CatId AND tbfiles.ModuleName = "projects"
                    WHERE tbprojects.ProjectName  LIKE CONCAT('%', @SearchWord , '%')
                          OR tbprojects.ProjectDesc  LIKE CONCAT('%', @SearchWord , '%')
                  ) AS v
    WHERE v.name != ''
    GROUP BY v.id;
  END //
DELIMITER ;

1 个答案:

答案 0 :(得分:2)

参数名称是SearchWord但您在过程正文中将其用作@SearchWord。删除@symbol,它将起作用