You must Sign In to post a response.
  • Category: .NET

    What is use of % in sql query ?

    By using Following query:--
    In Windows form,when I inserts any character in textbox,then it sort and shows records in listview from database as per my input.

    But if I inserts only % as input in textbox,then it shows all record in listview from database.
    Why ?

    /////////////////////////////////////////////////////////////////////////

    Select * from tblMaster_RawProduct_Details where RPName like '" + txtItemDiscription.Text + "%' order by RPName asc

    /////////////////////////////////////////////////////////////////////////
    Thank in Advance...
  • #724983

    Hi,

    I will give you some sample then you understand the requirement.

    For EX: in a database table having a column "name"

    the result would be like below

    name

    naveen
    navaneeth
    naren
    navya

    now i want to filter records based on name column

    EX:

    select * from table where name='naveen'


    output: naveen
    This will give you exact matching value.

    Ex2:

    select * from table where name like 'na%'


    output:

    naveen
    navaneeth
    naren
    navya

    This will give you the name starts with na and after that it might having any content.

    EX2:


    select * from table where name like 'nav%'


    output:

    naveen
    navaneeth
    navya


    in this ex naren should not come , why because in our searching i give condition the name should starts with 'nav' but in 'naren' the name starts with 'nar'. That's the reason naren is not in output result.

    Hope you understand the logic..


    --------------------------------------------------------------------------------
    Give respect to your work, Instead of trying to impress your boss.

    N@veen
    Blog : http://naveens-dotnet.blogspot.in/

  • #724984

    Hi Dinesh.
    % keyword is used in sql to show any number of records. In your query it will return all the RPName starting with txtItemDiscription and ending with any number of records.


    Thanks

    Reena

  • #724988
    Ok . I get understand that if I just enter only % in textbox , then it shows all records from database.
    Thanks Reena , Naveen Sanagasetti , Rakesh Chaubey and Anil Kumar Pandey Sir!

  • #724991

    Its the Wild card character that search the matching string.

    if only % is there it matches all thus gives you all records.


    Thanks & Regards
    Anil Kumar Pandey
    Microsoft MVP, DNS MVM

  • #724999
    Select * from Employee where emp_name like 'Rake%'.It is a wild card ..it will give all the name from that column which starts Rake
    Regards
    Rakesh Chaubey
    rakeshchaubey1989@gmail.com

  • #725053
    Hi Dinesh.
    Thanks for selecting my answer as best answer.

    Thanks

    Reena


  • This thread is locked for new responses. Please post your comments and questions as a separate thread.
    If required, refer to the URL of this page in your new post.