Solved

SQL Wildcard and @variable not working

Posted on 2004-08-10
1
513 Views
Last Modified: 2012-05-05
The wildcard is not working correctly with the variable for some reason.
If I put 2101% directly in the search string it works fine.
If I replace the @addrinfo.value = "2101" it doesn't work? or ="2101%"
I have also tried changing the @addrinfo datatype and no go.
I don't want to make a stored procedure if I don't have too.

Thanks so much for any help.

Dim viewall As New DataSet
        Dim getnumber = Split(Add_Address.Text, " ", -1, 1)
        Add_Site.Text = getnumber(0)
        Dim DetailStr As String = "SELECT HPLocID, Site, Mapsco, ServiceAddr, SiteType, City, Zip, Newmain, NewFax FROM Locations where ServiceAddr LIKE '@addrinfo%'"
        Dim cmd As New SqlCommand(DetailStr, MyConnection)
        Dim satlist As New SqlDataAdapter(cmd)

        cmd.Parameters.Add("@addrinfo", SqlDbType.NVarChar, 10)
        cmd.Parameters("@addrinfo").Value = getnumber(0)
        cmd.Parameters("@addrinfo").Direction = ParameterDirection.Input
        satlist.Fill(viewall, "Locations")
0
Comment
Question by:j_tipps
1 Comment
 
LVL 8

Accepted Solution

by:
boulder_bum earned 250 total points
ID: 11769124
It's literally trying to find '@addrinfo....' so it will find "@addrinfoPlus Extra Text", but not what you want it to.

Try " LIKE @addrinfo + '%' "
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Lots of people ask this question on how to extend the “MembershipProvider” to make use of custom authentication like using existing database or make use of some other way of authentication. Many blogs show you how to extend the membership provider c…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

789 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question