dan
dan

Reputation: 51

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'.

Upvotes: 1

Views: 50

Answers (1)

Rinto Antony
Rinto Antony

Reputation: 297

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)

Upvotes: 1

Related Questions