Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Database > SQL Language
|
SQL Language SQL Language discussions not specific to a particular RDBMS program or vendor.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the SQL Language section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old March 4th, 2007, 10:55 AM
Authorized User
 
Join Date: Mar 2007
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Default NEWBIE Question: Expected "" in search condition

Hello people and many thanks for taking the time to read this. I have the following problem and cant seem to find the answer anywhere.

I have a search page and a results page. The search page appends a query string to the url and the results page takes the query and does a search on the sql database. Now this is fine if I just enter 1 word but if I enter two words such as "West Kington" it produces the error in the title. If I do a manual search entering the quotes it works fine. How do I go about appending the quotes to the search?

Many thanks again

 
Old March 4th, 2007, 12:11 PM
Friend of Wrox
 
Join Date: Dec 2003
Posts: 488
Thanks: 0
Thanked 3 Times in 3 Posts
Default

Hey,

Don't know what language you're using to talk to your database but you could do something like this perl version:

Code:
$sql = "SELECT * FROM table WHERE NAME='$search_term'";
In ruby, you could say:

Code:
sql = "SELECT * FROM table WHERE NAME='#{search_term}'";
or in java:

Code:
String sql = new String( "SELECT * FROM table WHERE NAME='" + search_term + "'" );
The +s are the concatenation operator, in perl interpolation means you don't need to concatenate. You can google concatenation or interpolation for your language.

HTH


--
Charlie Harvey's website - linux, perl, java, anarchism and punk rock: http://charlieharvey.org.uk
 
Old March 4th, 2007, 12:17 PM
Authorized User
 
Join Date: Mar 2007
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks for the reply. I am actually working with ASP.net and here is the code

<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ListingDBConnectionString %>"
            SelectCommand="SELECT [CompName], [Town], [Tele] FROM [CompanyDetails] WHERE (([CompName] = @CompName) OR (CONTAINS([CompName], @CompName2))) ORDER BY [CompName]">
            <SelectParameters>
                <asp:QueryStringParameter Name="CompName" QueryStringField="cn" Type="String" />
                <asp:QueryStringParameter Name="CompName2" QueryStringField="cn" Type="String" />
            </SelectParameters>
        </asp:SqlDataSource>

 
Old March 13th, 2007, 10:29 AM
Registered User
 
Join Date: Mar 2007
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

In VB .NET, you can put quotation marks around a string like this:

Dim strTest = """" & stringToQuote & """"

(Note the two sets of four double quote characters!)

In C#, do this:

string strTest = "\"" + stringToQuote + "\""

\" is the escape sequence for a double quote and (of course) you have to surround it with double quote characters as well. So we have three instead of four.

If you do that with the string before appending it to the url, it should solve your problem.

Irene
 
Old March 13th, 2007, 10:36 AM
Wrox Author
 
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

Alternatively you could do

VB.NET
Dim sSql = "SELECT * from table where value = '" & variable & "'"
C#
string sSql = "SELECT * from table where value = '" + variable + "'";

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
^^Took that from planoie's profile^^
^^Modified text taken from gbianchi profile^^
================================================== =========
Technical Editor for: Professional Search Engine Optimization with ASP.NET
http://www.wiley.com/WileyCDA/WileyT...470131470.html
================================================== =========
Why can't Programmers, program??
http://www.codinghorror.com/blog/archives/000781.html
================================================== =========
 
Old March 19th, 2007, 03:49 PM
Registered User
 
Join Date: Mar 2007
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Or
DIM q$
q$ = chr$(34)

sSQL = "SELECT * FROM table WHERE value = " & q$ & variable & q$ & ";"

Best wishes,
BW





Similar Threads
Thread Thread Starter Forum Replies Last Post
Expected values in a condition, XPath 1.0 akentanaka XSLT 2 June 27th, 2008 05:48 AM
Search Condition tmadhavi SQL Server 2000 2 February 21st, 2008 03:13 AM
NEWBIE Question: Expected "" in search condition aasiddle ASP.NET 2.0 Basics 0 March 4th, 2007 11:21 AM
Help PLZ..Condition for Search Page shopgirl Classic ASP Databases 4 April 5th, 2004 10:59 PM
WHERE BETWEEN search condition in sproc jtyson SQL Server 2000 1 August 7th, 2003 09:22 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.