VBLady Posted November 6, 2003 Posted November 6, 2003 I need some help with this: I am trying to build an sql query in a string and I am having a hard time getting the end quote on the string! I've tried this: sQuery = "select myfield from mytable where thisvalue= '" & sMyVariable & "'" and I've tried: sQuery = [string].concat("select myfield from mytable where thisvalue = '", sMyVariable, "'") BOTH of them result in the following string select myfield from mytable where thisvalue = 'thevalueofthevar With NO end quote!! This is of course causing my sql query to fail. The variable sQuery is long enough. Please help! Frances Quote
Moderators Robby Posted November 6, 2003 Moderators Posted November 6, 2003 If thisvalue is of string type in the table then you'refirst one is correct. If the field is numeric then sQuery = "select myfield from mytable where thisvalue= " & sMyVariable Quote Visit...Bassic Software
Administrators PlausiblyDamp Posted November 6, 2003 Administrators Posted November 6, 2003 Just tried it here and it worked fine. Are both sQuery and sMyVariable defined as strings? If so what are you assigning to sMyVariable? Also could you show the code leading up to this? Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
VBLady Posted November 7, 2003 Author Posted November 7, 2003 Here is the code: sAccountno = New String(Chr(0), 22) GMW_DB_Read(lWA, "Accountno", sAccountno, 22) GMW_DB_Delete(lWA) GMW_DB_Close(lWA) lWA = GMW_DB_Open("Contact2") GMW_DB_SetOrder(lWA, "CONTACT2") iResult = GMW_DB_Seek(lWA, sAccountno) If iResult = 1 Then GMW_DB_Delete(lWA) End If GMW_DB_Close(lWA) sQuery = New String(Chr(0), 256) sQuery = [string].Concat("select recid from contsupp where accountno = '", sAccountno, "'") sAccount is declared as a string. And Robby, I know that numeric values in an sql query do not have quotes around them. That has nothing to do with my question. I need quotes around this value, but the trailing quote is not showing up. Quote
Mehyar Posted November 7, 2003 Posted November 7, 2003 Are you sure your string variable does not contain a ' Just a thought... Quote Dream as if you'll live forever, live as if you'll die today
Administrators PlausiblyDamp Posted November 7, 2003 Administrators Posted November 7, 2003 You are filling the string with null values (Chr(0)). The nulls are probably acting as a string terminator. Is there any reason you are padding it with nulls? Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
VBLady Posted November 7, 2003 Author Posted November 7, 2003 The C++ API I am passing the strings to requires them to be initialized with the nulls. If I don't, they don't get populated. Quote
Administrators PlausiblyDamp Posted November 7, 2003 Administrators Posted November 7, 2003 You may need to build the string and then pad it with nulls to the required size. Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
VBLady Posted November 7, 2003 Author Posted November 7, 2003 Isn't that what I'm already doing with the sAccountno = New String(chr(0),22) ??? Quote
Administrators PlausiblyDamp Posted November 7, 2003 Administrators Posted November 7, 2003 How does the sAccountno get filled in - I'm guessing inside the C dll. Have you tried stripping the nulls from the variable after it is returned from the DLL function? Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
pendragon Posted November 7, 2003 Posted November 7, 2003 PlausiblyDamp beat me to it, If there is a null at the end of sAccountno anything to the right of it will be lost. :D Quote
VBLady Posted November 7, 2003 Author Posted November 7, 2003 That's just lame. The concat should append up to the null in sAccountno and then add on the end quote. It worked fine in VB6. How do I strip the end nulls from the sAccountno? Quote
pendragon Posted November 7, 2003 Posted November 7, 2003 sAccountno = sAccountno.replace(Chr(0), "") worked on my test program. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.