Mohamad Kiani
Mohamad Kiani

Reputation: 15

Counts number of rows with like in SQL Server

I have a SQL Server database. I want to count number of rows where the id starts from 1112 . (id is string and its format in data base is nchar(7))

I have 20 rows that start from 1112 like 1112000, 1112001, 1112002,....

But when I write this query returns 0!.

SELECT COUNT(*) AS num
FROM table
WHERE (id LIKE '1112*')

Upvotes: 0

Views: 113

Answers (2)

Mehmet Aydın
Mehmet Aydın

Reputation: 11

try % instead of *

"id LIKE '1112%')

Upvotes: 0

Mikael Eriksson
Mikael Eriksson

Reputation: 138960

You should use % instead of *.

SELECT        COUNT(*) AS num
FROM           table
WHERE        (id LIKE '1112%')

LIKE (Transact-SQL)

Upvotes: 2

Related Questions