Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQL Server : why are there no rows found?

When I use this query:

SELECT TOP 20 
     f.name as f_firm_name 
FROM Firm f 
WHERE f.id_city = '73041' COLLATE SQL_Latin1_General_Cp1251_CI_AS 
ORDER BY f.name ASC

I get these results:

f_firm_name
--------------------------------
 SKY  LINE STUDIO
 АНТИКВАРНЫЙ САЛОН
 БИЗОН УЛЬЯНОВСК
 ВЕРТЕКС ЗАО
 ВОЗРОЖДЕНИЕ+
 ВОЛГАСПЕЦТЕХНОЛОГИИ
 ГП СЕРВИС
 Данилов А.Б.ИП
 ИНИКОМ
 ИП МАЛАШИН В.Б.
 ИП СУЛАГАЕВ АНДРЕЙ

(20 row(s) affected)

But if I use this query:

SELECT TOP 20 
     f.name as f_firm_name 
FROM Firm f 
WHERE f.id_city='73041'
  AND f.name LIKE 'ВЕРТЕКС ЗАО%' COLLATE SQL_Latin1_General_Cp1251_CI_AS 
ORDER BY f.name ASC

I get these results:

f_firm_name
-----------------
(0 row(s) affected)

Why am I getting 0 rows if in the first query I get f.name and use that result to search in the second query?

like image 950
Leo Loki Avatar asked Jun 05 '13 10:06

Leo Loki


People also ask

Why it is showing no rows selected in SQL?

no rows selected simply means that your table emp has no record at all.

Why is my query returning 0 rows?

The second most common issue that produces 0 rows returned is that the query is filtering out too much data in the WHERE or HAVING statement. To see if the WHERE or HAVING clause is too restrictive simply remove it from the query to see if any rows are returned.

How show all rows in SQL?

SELECT * FROM <TableName>; This SQL query will select all columns and all rows from the table.

What does SQL select return if nothing is found?

Description. The IS NULL condition is used in SQL to test for a NULL value. It returns TRUE if a NULL value is found, otherwise it returns FALSE. It can be used in a SELECT, INSERT, UPDATE, or DELETE statement.


1 Answers

Possible, the first character in f_firm_name - is a space.

So try this one -

SELECT TOP 20 f_firm_name = f.name  
FROM dbo.Firm f 
WHERE f.id_city = '73041'
    AND LTRIM(f.name) LIKE 'ВЕРТЕКС ЗАО%' --<--
        COLLATE SQL_Latin1_General_Cp1251_CI_AS 
ORDER BY f.name
like image 185
Devart Avatar answered Oct 28 '22 22:10

Devart