none
Sql Equal RRS feed

  • Question

  • HI

    i used this query to search and debug a problem
    In the search process if i search the employee code, for example code ; e1,e2,e3,e10,e100 ..

    If i want to search the code for the employee code = e1 .

    that appears with me    e1,e10,e100
    I want the search result to match exactly the length of the text and the value and show only one value = e1

      Dim DataAdapter As New OleDbDataAdapter("SELECT *  FROM  EMPLOYEDETAILS_TB WHERE EMPLOYE_SHOWHIDE =true  AND EMPLOYE_CODE = " & Trim$(Me.TXTSEARCH.Text) & " ORDER BY EMPLOYE_ID", con)



    • Edited by ahmeddc Wednesday, March 20, 2019 8:04 AM
    Wednesday, March 20, 2019 8:03 AM

Answers

  • database access 2007

    When searching for a code, I only want to show one value
    When I want to search for the first employee code = em1

    show em1  only 


    When query for string you need to include single quotes on the string value in WHERE clause, or use SqlCOmmand.Parameters 

    IE

            Using MyCmd As New SqlCommand("SELECTS * FROM Table WHERE Employee_Code=@EmpCode", MyConnection)
                MyCmd.Parameters.AddWithValue("@EmpCode", LTrim(RTrim(MyTextbox.Text)))
            End Using

    Im not sure if Trim will trim both left and right, if so you could use only the Trim function 


    Live as if you were going to die today, learn as if you were going to live forever -Mahatma Gandhi

    • Marked as answer by ahmeddc Wednesday, March 20, 2019 3:24 PM
    Wednesday, March 20, 2019 1:56 PM

All replies

  • Hi,

    I think your code will only show the result of e1,if you want to appear with you e1,e10,e100,use Fuzzy query.

     Dim DataAdapter As New OleDbDataAdapter("SELECT *  FROM  EMPLOYEDETAILS_TB WHERE EMPLOYE_SHOWHIDE =true  AND EMPLOYE_CODE like " & "'" & Trim$(Me.TXTSEARCH.Text) & "%" & "'" & " ORDER BY EMPLOYE_ID", con)

    Best Regards,

    Alex


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Wednesday, March 20, 2019 9:23 AM
  • Hi,

    I think your code will only show the result of e1,if you want to appear with you e1,e10,e100,use Fuzzy query.

     Dim DataAdapter As New OleDbDataAdapter("SELECT *  FROM  EMPLOYEDETAILS_TB WHERE EMPLOYE_SHOWHIDE =true  AND EMPLOYE_CODE like " & "'" & Trim$(Me.TXTSEARCH.Text) & "%" & "'" & " ORDER BY EMPLOYE_ID", con)

    Best Regards,

    Alex


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    The problem is as come on
    Wednesday, March 20, 2019 11:35 AM
  • If you are using MS SQL Server, then way are you not using MS SQL Server Management Stuido to run, test and debug the T-SQL statement?
    Wednesday, March 20, 2019 11:49 AM

  • The problem is as come on

    Hello,

    What do you mean, your sentence makes no sense.


    Please remember to mark the replies as answers if they help and unmarked them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.

    NuGet BaseConnectionLibrary for database connections.

    StackOverFlow
    profile for Karen Payne on Stack Exchange

    Wednesday, March 20, 2019 11:52 AM
    Moderator
  • The problem is unresolved

    When the search is done e1
    The result is

    e1,e10,e11,e12,e13,e100

    Wednesday, March 20, 2019 12:02 PM
  • You might consider taking a screenshot of the data for this field then describe what you want.

    When I look at e1,e10,e11,e12,e13,e100 my first thought is if this is one field you should consider rethinking the database tables to better represent the data rather than using (as I see it) a delimited string.


    Please remember to mark the replies as answers if they help and unmarked them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.

    NuGet BaseConnectionLibrary for database connections.

    StackOverFlow
    profile for Karen Payne on Stack Exchange

    Wednesday, March 20, 2019 12:09 PM
    Moderator
  • database access 2007

    When searching for a code, I only want to show one value
    When I want to search for the first employee code = em1

    show em1  only 


    • Edited by ahmeddc Wednesday, March 20, 2019 1:33 PM
    Wednesday, March 20, 2019 12:24 PM
  • database access 2007

    When searching for a code, I only want to show one value
    When I want to search for the first employee code = em1

    show em1  only 


    When query for string you need to include single quotes on the string value in WHERE clause, or use SqlCOmmand.Parameters 

    IE

            Using MyCmd As New SqlCommand("SELECTS * FROM Table WHERE Employee_Code=@EmpCode", MyConnection)
                MyCmd.Parameters.AddWithValue("@EmpCode", LTrim(RTrim(MyTextbox.Text)))
            End Using

    Im not sure if Trim will trim both left and right, if so you could use only the Trim function 


    Live as if you were going to die today, learn as if you were going to live forever -Mahatma Gandhi

    • Marked as answer by ahmeddc Wednesday, March 20, 2019 3:24 PM
    Wednesday, March 20, 2019 1:56 PM
  • database access 2007

    When searching for a code, I only want to show one value
    When I want to search for the first employee code = em1

    show em1  only 


    When query for string you need to include single quotes on the string value in WHERE clause, or use SqlCOmmand.Parameters 

    IE

            Using MyCmd As New SqlCommand("SELECTS * FROM Table WHERE Employee_Code=@EmpCode", MyConnection)
                MyCmd.Parameters.AddWithValue("@EmpCode", LTrim(RTrim(MyTextbox.Text)))
            End Using

    Im not sure if Trim will trim both left and right, if so you could use only the Trim function 


    Live as if you were going to die today, learn as if you were going to live forever -Mahatma Gandhi

    excellent

    thanks  gtripodi



    • Edited by ahmeddc Wednesday, March 20, 2019 3:23 PM
    Wednesday, March 20, 2019 3:22 PM