CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Feb 2001
    Posts
    33

    Stored Procedure

    CREATE PROCEDURE sp_SearchName
    @v2 char

    AS
    select name, sex from inf_tbl where name like @v2%

    If the user input 'M' , the procedure can show all names start from 'Mxxxx',
    but I can't show this .
    What's wrong with this procedure ?
    I think there is something wrong with operator 'like'.



  2. #2
    Join Date
    Oct 2000
    Location
    JHB South Africa
    Posts
    27

    Re: Stored Procedure

    Hi.

    No there is nothing wrong with 'like'.

    Try to concatenate the variable @v2 before inserting it into the select statement.
    - Select @v2 = @v2 + '%'
    - Select Name, Sex from Inf_Tbl where name like @v2.
    (alternatative)
    You may want to concatenate the '%' to the variable in your VB code before calling the stored proc. Then you would not need to do it in the stored proc

    Let me know if you still have problems



  3. #3
    Join Date
    Feb 2001
    Posts
    33

    Re: Stored Procedure

    It can't work !!!

    e.g. suppose chosen = "M"
    chosen = chosen + '%' ----> here is the problem

    sql = "Select * from inf_tbl where name like " & _
    "'" & chosen & "'" & " order name"


  4. #4
    Join Date
    Oct 2000
    Location
    JHB South Africa
    Posts
    27

    Re: Stored Procedure

    A typical 'like' Statement :

    Select * from Table where Name like 'A%'
    and not
    Select * from Table where Name like 'A'%

    This is how your Supposed values must look before submitting it into the SQL string :
    - suppose chosen = "M%"

    Remember that the '%' sign is part of the value and not of the statement

    Also don't confuse yourself with complicated concatenations :
    Your line of code :
    - sql = "Select * from inf_tbl where name like " & _
    "'" & chosen & "'" & " order name"
    My line of code:
    - sql = "Select * from inf_tbl where name like '" & chosen & "' order by Name"



  5. #5
    Join Date
    Feb 2001
    Posts
    33

    Re: Stored Procedure

    It can work now !!!
    wbeetage, thank you much for helping me to solve this problem !


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured