Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Thanks to help me

Status
Not open for further replies.

Ologhai

Programmer
Apr 11, 2000
42
CA
look at that. <br><br>temp = &quot;O'KEEFE LTD.&quot;<br>wSQL = &quot;SELECT * FROM manuf WHERE descrip='&quot; & temp & &quot;'&quot;<br>recSQL.Open wSQL, ConSQL, adOpenDynamic, adLockOptimistic<br><br>this doesn't work because the select is that<br>SELECT * FROM manuf WHERE descrip='O'KEEFE LTD.'<br><br>i tried this<br><br>temp = &quot;O'KEEFE LTD.&quot;<br>wSQL = &quot;SELECT * FROM manuf WHERE descrip=&quot; & chr(34) & temp & chr(34) & &quot;<br>recSQL.Open wSQL, ConSQL, adOpenDynamic, adLockOptimistic<br><br>this doesn't work because the select is that<br>SELECT * FROM manuf WHERE descrip=&quot;O'KEEFE LTD.&quot;<br>and the error is &quot;can't find this column&quot;<br><br>someone have idea ?
 
Hi , <br>I tried this on my MS SQL server and it worked. I don't whether this answers your question or not. <br><br>Declare @temp1 varchar(20) <br>set @temp1 = &quot;Aztec&quot;<br>SELEcT * FROM foo WHERE field1 = @temp1 <br><br><br>Thanx<br>Siddhartha Singh<br><A HREF="mailto:ssingh@aztecsoft.com">ssingh@aztecsoft.com</A><br><br><br>
 
Yes,<br><br>There is a ' in the string ie &quot;O'KEENE LDT.&quot;<br>When sending the string to SQL Server, the string will look like this:<br><br>SELECT * FROM manuf WHERE descrip='XXXX' and VEND_NM<br>= 'O'KEENE LDT.'<br><br>You need to put a doble quote in the sting you are searching for ie.<br><br>temp = &quot;O''KEEFE LTD.&quot;&nbsp;&nbsp;&nbsp;&lt;---------------------------<br><br>wSQL = &quot;SELECT * FROM manuf WHERE descrip='&quot; & temp & &quot;'&quot;<br><br>Write a small function that checks if a sting has a single quote in it and replaces the quote with two single quotes ''<br><br>Hope this helps<br><br>CD<br><br>
 
Since it looks like you're using VB and maybe ADO, You could avoid the whole mess if you can use stored procs.&nbsp;&nbsp;And it will be much faster having a pre-compiled execution plan.<br><FONT FACE=monospace><br>&nbsp;&nbsp;&nbsp;&nbsp;CREATE PROCEDURE myStoredProc_p <br>&nbsp;&nbsp;&nbsp;&nbsp;@descrip varChar(50)<br>&nbsp;&nbsp;&nbsp;&nbsp;AS<br>&nbsp;&nbsp;&nbsp;&nbsp;SELECT * FROM manuf WHERE descrip = @UserId<br></font><br>Then your VB code...<br><FONT FACE=monospace><br>&nbsp;&nbsp;&nbsp;&nbsp;strSP = &quot;myStoredProc_p&quot;<br>&nbsp;&nbsp;&nbsp;&nbsp;<b>temp</b> = &quot;O'KEEFE LTD.&quot;<br><br>&nbsp;&nbsp;&nbsp;&nbsp;Set rs = CreateObject(&quot;ADODB.Recordset&quot;)<br>&nbsp;&nbsp;&nbsp;&nbsp;Set cmd = CreateObject(&quot;ADODB.Command&quot;)<br><br>&nbsp;&nbsp;&nbsp;&nbsp;cmd.ActiveConnection = ConnectionString<br>&nbsp;&nbsp;&nbsp;&nbsp;cmd.CommandText = strSP<br>&nbsp;&nbsp;&nbsp;&nbsp;cmd.CommandType = adCmdStoredProc<br><br>&nbsp;&nbsp;&nbsp;&nbsp;cmd.Parameters.Append cmd.CreateParameter _<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(&quot;@descrip&quot;,adVarChar, adParamInputput, 50, <b>temp</b>)<br><br>&nbsp;&nbsp;&nbsp;&nbsp;rs.Open cmd, , adOpenForwardOnly, adLockReadOnly<br></font><br>
 
Quite right Ed.<br><br>Personally, I think that all interaction with the database (especially updates, inserts and deletes) should be carried out through stored procedures so that they act as an API for your database.
 
Couldn't agree more with both Ed and jnicho.&nbsp;&nbsp;SP's are also massively faster than attempting to use the high-level stuff if you do anything complex, because each statement tends to get 'wrapped' in a bunch of crud by the ODBC.&nbsp;&nbsp;I measured a fifteen-fold performance difference between using an SP and a sequence of ADO operations on one database!
 
You really have the same roblem twice.&nbsp;&nbsp;The language has to deal with string delimiters, then the SQL engine does too.<br><br>First get it working in a query designer, that will get the SQL syntax nailed.&nbsp;&nbsp;Then work to create the string you made in the QD.<br><br><br>Create this string( I put spaves before and after the statement for readability:)<br><br>&quot; SELECT * from manuf where descrip = &quot;&quot;O'KEEFE LTD.&quot;&quot; &quot;<br><br>with var <br>&quot;SELECT * from manuf where descrip = &quot;&quot;&quot;&var&&quot;&quot;&quot; &quot;<br><br>but in VB<br><br>&quot; &quot;&quot;SELECT * from manuf where descrip = &quot;&quot;&quot;&quot;&quot;&quot;&var&quot;&quot;&quot;&quot;&quot;&quot;&quot;&quot; &quot;<br><br><br>or<br><br>Check the manual of whatever your DB is, and look to see how to make the ' a literal rather than a delimiter.<br><br><br><br>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top