0

I am new to working with azure, and I moved a database that I used to work with locally via ms sql. After that, the query below returns 0 rows in azure, and 1 row in ms sql. All tables are identical and contain the same data. What could be the problem?

SELECT q.Id, q.Title
FROM Questions AS q
    JOIN TagsQuestions AS tq
        ON q.Id = tq.QuestionForeignKey
    JOIN Tags AS t
        ON t.Id = tq.TagForeignKey 
WHERE t.Name IN ('C#') AND q.Title Like '%пересечение%'
GROUP BY q.Id, q.Title
HAVING COUNT(*) = 1
Макс
  • 95
  • 4
  • 3
    `Like '%пересечение%'` without using `nvarchar` smells fishy. Different collations? – Thom A Apr 07 '20 at 11:28
  • In ms sql, this field nvarchar, in azure created for the same migration, should also be in the idea of nvarchar. – Макс Apr 07 '20 at 11:30
  • 1
    But `'%пересечение%'` is ***not*** an `nvarchar`, it's a `varchar`. Hence my question of if you're using different collations in the different environments. – Thom A Apr 07 '20 at 11:31
  • 1
    Does this answer your question? [What is the meaning of the prefix N in T-SQL statements and when should I use it?](https://stackoverflow.com/q/10025032/2029983) – Thom A Apr 07 '20 at 11:32
  • what should I do? To change to varchar? But why does everything work in ms sql – Макс Apr 07 '20 at 11:33
  • *"But why does everything work in ms sql"* Again, *are you using different collations?* – Thom A Apr 07 '20 at 11:34
  • 1
    What does `SELECT collation_name FROM sys.databases WHERE [name] = N'YourDatabase';` return on your respective instances (obviously replace the value of YourDatabase with the correct database name). – Thom A Apr 07 '20 at 11:35
  • now I'll try with "N" – Макс Apr 07 '20 at 11:36
  • 1
    I have marked this as a duplicate, as I have no doubts that the exclusion of the `N` prefix is the reason why this isn't working. The *likely* reason you are getting different behaviours is because you are using different collations, and so characters like `ч` aren't in the code page of the database hosted in Azure. Considering, however, that your column is an `nvarchar` you should be using the `N` prefix anyway. I do, however, suggest you look at your collations, as consistancy is important (especially if you have used literal `varchar`s instead of `nvarchar`s across your SQL). – Thom A Apr 07 '20 at 11:39
  • the "N" prefix helped, thank you – Макс Apr 07 '20 at 11:41

0 Answers0