dan dan - 4 months ago 10
SQL Question

How can I add '%' to my select of SQL-Server

I want to get count of one table, also I want to show list of GeoID.
The problem is I can't add '%' to my where

SELECT GeoTitle AS Expr1,GeoId , (GeoId+'%') as moh,
(SELECT count( Product.ProductId)
FROM Company INNER JOIN
Product ON Company.CompanyId = Product.CompanyId
WHERE (Company.GeoId LIKE moh))

FROM GeoLanguage
WHERE (LanguageId = 1)


Error: Invalid column name 'moh'.

Answer

Try this

SELECT        A.GeoTitle AS Expr1,A.GeoId,
    (SELECT       count( Product.ProductId)
    FROM            Company INNER JOIN
                             Product ON Company.CompanyId = Product.CompanyId
    WHERE        (Company.GeoId LIKE A.GeoId+'%'))

    FROM            GeoLanguage as A
    WHERE        (A.LanguageId = 1)