how to search a text on a database

  • Hello:

    I want to ask for a variable anf then search it on a database.

    I have this:

    declare @key as varchar(50)

    set @key LIKE ‘% /* T1.Dscription*/%’ '[%0]'

    SELECT T0.[DocNum], T0.[CardCode],T1.[ItemCode], T1.[Quantity], T1.[Dscription], T1.[Price] FROM OQUT T0 INNER JOIN QUT1 T1 ON T0.DocEntry = T1.DocEntry

    WHERE T1.Dscription = @key

    the problem is that it needs exactly all the text of description for work and i want to search a part of it.

    For example :

    If description = Reparation

    I want to search whith the key: Repa

  • To do what you're looking for requires you to change your code to dynamic T-SQL. However, that also exposes you to SQL Injection attacks, so you'll have to write additional code to ensure that doesn't happen. First, I'd suggest using sp_executesql to build and execute the dynamic T-SQL. There are examples online that will show you how to do it. Then, you'll need to validate the information in the parameter on both the front-end and the back-end to avoid SQL Injection.

    "The credit belongs to the man who is actually in the arena, whose face is marred by dust and sweat and blood"
    - Theodore Roosevelt

    Author of:
    SQL Server Execution Plans
    SQL Server Query Performance Tuning

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

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