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!

I have a problem when i am trying t

Status
Not open for further replies.

telesync

Programmer
Sep 27, 2002
4
US
I have a problem when i am trying to query table that have space in the name. For eg i have table "part master". when i use a asp page to query this table inorder to use quotes around that table i have written the code as shown below. I am not happy with is rude method of adding code around the table. This code does work but would like to have better implementation. Any suggestion will be greatly appreciated.

the script that have written is as shown below
<html>
<head>
<meta NAME=&quot;GENERATOR&quot; Content=&quot;Microsoft Visual Studio 6.0&quot;>

<body>

<%

Dim objConn
dim var
'Creating a variable to store &quot;

strDQuote = chr(34)
Set objConn = server.CreateObject(&quot;ADODB.Connection&quot;)

'Use the next line for and DSN connection
objConn.ConnectionString = &quot;DSN=test&quot;
objConn.Open

' using the strDQuote to be added around the table.
' I have tried these options but they all give errors
' mysql=&quot;select * from part master&quot;
' mysql=&quot;select * from&quot; & &quot;part master&quot;
' The option give below works fine but will be very hard to use when i dealing with very long queries. If there is better please do send your suggestions.

mysql=&quot;select * from &quot; & strDQuote & &quot;part master&quot; & strDQuote

set rstemp=objconn.execute(mysql)
if rstemp.eof then
response.write &quot;no records found&quot;
response.write mysql
objconn.close
set objconn=nothing
response.end
end if
do while not rstemp.eof
response.write &quot;First field &quot;& rstemp(&quot;PRTNUM_01&quot;) & &quot;<br>&quot;
response.write &quot;second field &quot;& rstemp(&quot;type_01&quot;)
rstemp.MoveNext

Loop

rstemp.close
set rstemp=nothing
objConn.Close
set objConn=nothing
%>
</body>
</html>

If any body has worked with table name with spaces(i.e part master and not partMaster) and used them in asp pages to query the tables please do let me know.

Thank You in Advance,

 
The escape character for a double quote in a string is just double double quotes, for example:
Code:
mysql=&quot;select * from &quot;&quot;part master&quot;&quot;&quot;
would replace your similar line in the above code. this should work utilizing less space than above, and while it can still look a little confusing, I think it looks less confusing than concatenating in another variable.
-Tarwn &quot;The problem with a kludge is eventually you're going to have to back and do it right.&quot; - Programmers Saying (The Wiz Biz - Rick Cook)
&quot;Your a geek!&quot; - My Girlfriends saying
 
Thank you tarwn for having replied to my request.

I have tried that in the string but that gives me a syntax error. Hence had to take the above approach that i have mentioned above. I agree i will have to change the way i am doing it but cannot something more easier and something that will work.

Any other suggestions will definately be helpful

 
Have you tried this:
Code:
mysql=&quot;select * from [part master]&quot;
This is not a bug - it's an undocumented feature...
;-)
 
I know thats not a bug. I have tried that, this cannot be used in a string directly. It would give an syntax error.

mysql=&quot;select * from [part master]&quot;;

I will have to use one of the approaches as show in the code above.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top