Click to See Complete Forum and Search --> : HELP: How do I play the string concatenation in sql statement right


yts007
01-12-2006, 05:13 AM
Am getting this error message when running this sql statement in dreamweaver mx 2004 with ms access db:

Microsoft VBScript compilation (0x800A0408)
Invalid character

-------------------- the select statement ----------------

"SELECT tblBooks.Title, tblBooks.No_pages, tblBooks.Price, tblBooks.Availability, tblBooks.AuthorName, tblBooks.Out_Of_List, tblBooks.Img_url, tblBookSizes.Size_Desc, tblAuthors.Author_Name, tblCategory.Category_Desc, tblEditions.Edition_Desc, tblPublishers.Publisher_Name, tblYears.Year_Desc FROM tblYears INNER JOIN (tblPublishers INNER JOIN (tblEditions INNER JOIN (tblCategory INNER JOIN (tblBookSizes INNER JOIN (tblAuthors INNER JOIN tblBooks ON tblAuthors.Author_id = tblBooks.Author_id) ON tblBookSizes.Size_no = tblBooks.Size_no) ON tblCategory.Category_id = tblBooks.Category_id) ON tblEditions.Edition_no = tblBooks.Edition_no) ON tblPublishers.Publisher_id = tblBooks.Publisher_id) ON tblYears.Year_id = tblBooks.Year_id WHERE (((tblBooks.Title) Like "%" + Replace(Recordset1__vtitle, "'", "''") + "%")) OR (((tblBooks.AuthorName) Like "%" + Replace(Recordset1__vauthorname, "'", "''") + "%"))"

------------------------------------------------

anybody can suggest a good artical, book, post that explain string concatenation, how to read, usage single quotes double quotes. pls

jvanamali
01-12-2006, 06:22 AM
sql ="SELECT tblBooks.Title, tblBooks.No_pages, tblBooks.Price, tblBooks.Availability, tblBooks.AuthorName, tblBooks.Out_Of_List, tblBooks.Img_url, tblBookSizes.Size_Desc, tblAuthors.Author_Name, tblCategory.Category_Desc, tblEditions.Edition_Desc, tblPublishers.Publisher_Name, tblYears.Year_Desc FROM tblYears INNER JOIN (tblPublishers INNER JOIN (tblEditions INNER JOIN (tblCategory INNER JOIN (tblBookSizes INNER JOIN (tblAuthors INNER JOIN tblBooks ON tblAuthors.Author_id = tblBooks.Author_id) ON tblBookSizes.Size_no = tblBooks.Size_no) ON tblCategory.Category_id = tblBooks.Category_id) ON tblEditions.Edition_no = tblBooks.Edition_no) ON tblPublishers.Publisher_id = tblBooks.Publisher_id) ON tblYears.Year_id = tblBooks.Year_id WHERE (((tblBooks.Title) Like '%" + Replace(Recordset1__vtitle, "'", "''") + "%')) OR (((tblBooks.AuthorName) Like '%" + Replace(Recordset1__vauthorname, "'", "''") + "%'))"

only the double quote before after the % character should be single quote

to keep it simple try this

where ever u concat a variable , i.e just before and after the plus symbol u can use double quotes else where in the string use single quote

i.e

between every double quotes opening and closing there won't won't another double quote

this might not be the correct method of going about it but definetly an easier method

yts007
01-12-2006, 07:15 AM
it worked, thank you.
is there any good artical that explain this?