none
Query with SqlParameters odd result RRS feed

  • Question

  •  

    Hi, I have a .NET application using a lot of query using Sql parameters. Today I stumbled on something really strange. My query wasn't returning anything even if I knew the data exist.

     

    exec sp_executesql N'SELECT CityId FROM [City] WHERE Name LIKE @Name',N'@Name varchar(19)',@Name=N'St-Jean Chrysostome'

     

    exec sp_executesql N'SELECT CityId FROM [City] WHERE Name LIKE @Name',N'@Name nvarchar(19)',@Name=N'St-Jean Chrysostome'

     

    These two are identical beside the fact that the sql parameter is nvarchar for the first one, and varchar for the second one. The first is the one generated in my application, which return nothing, and the second is the corrected one that work.

     

    I'd like to know why is the first one returning nothing. The input string is still the same... (My column in the database is varchar.) Thank.

    Friday, October 5, 2007 7:54 PM