user2448358
user2448358

Reputation: 17

SQL result differ but no error

There's something I don't get. I tried to get a result with a SQL query in C# but it's not working so I tried it in SQL Server Management Studio. My first attempt was the first query which works as supposed to, but to be as close as how I wrote it in C#, I did the second one but, as in my C# app, it returns no result.

Here is the code:

select quincid 
from itemsquinc
where code_produit like '%MPB79 - 4 1/2 x 4 - 652 (26D)%'

and

declare @test nvarchar(max)
set @test = '"MPB79 - 4 1/2 x 4 - 652 (26D)"'

select quincid 
from itemsquinc
where code_produit like '%@test%'

Can someone explain me why the second one is not returning any results?

Thanks

Upvotes: 0

Views: 49

Answers (1)

paparazzo
paparazzo

Reputation: 45096

You are searching on the literal @test not variable @test

declare @test nvarchar(max) set @test = 'MPB79 - 4 1/2 x 4 - 652 (26D)'

select quincid  from itemsquinc where code_produit like '%' + @test + '%'

Upvotes: 2

Related Questions