Sql Queries in Vb.net

  • Hi

    When running such sql queries in vb.net SELECT * FROM VsrData WHERE RaceTitle Like '%{0}%'" and SELECT * FROM VsrData WHERE Venue=@Venue,

    what is required to perform the inverse query.

    Thanks

  • Describe what you mean inverse query. If you simply mean to get the opposite set of rows for the two queries then use NOT LIKE and or !=. Of course these are not sargable, so you can expect a performance hit from using them, as they generally cause scans over seeks.

    One thing I see that you should be aware of is your first query

    SELECT * FROM VsrData WHERE RaceTitle Like '%{0}%'"

    can be a SQL Injection problem. You should still parameterize this

    SELECT * FROM VsrData WHERE RaceTitle Like @RaceTitle

    You can add the % wildcard to the front and back of the string that you assign to the @RaceTitle parameter, and it will function identically to concatenating the value into the command. The difference is that you get better plan caching, and it removes the risk of SQL Injection.

    Jonathan Kehayias | Principal Consultant | MCM: SQL Server 2008
    My Blog | Twitter | MVP Profile
    Training | Consulting | Become a SQLskills Insider
    Troubleshooting SQL Server: A Guide for Accidental DBAs[/url]

Viewing 2 posts - 1 through 1 (of 1 total)

You must be logged in to reply to this topic. Login to reply