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?
no rows selected simply means that your table emp has no record at all.
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.
SELECT * FROM <TableName>; This SQL query will select all columns and all rows from the table.
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With