Replacing Quotation marks in SQL

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • nonni
    New Member
    • Mar 2007
    • 1

    Replacing Quotation marks in SQL

    Hi.

    I came across this site while looking for a function to replace Quotation marks in SQL.

    This is my code.

    <!-- Begin Code -->

    Intro = Replace(Intro," '","''")
    Text = Replace(Text,"' ","''")



    SQL = "Insert Into Articles(Author Id,CatId,Topsto ryId,Headline,S ubheadline,Intr o,Text) Values ('" & Request("Author Id") & "','" & Request("CatId" ) & "','" & Request("TopSto ryId") & "','" & Request("Headli ne") & "','" & Request("Subhea dline") & "','" & Intro & "','" & Text &"')"

    <!-- End Quote -->


    Now the problem I have is that when I execute my sql server statement no value is written in the database for Intro and Text, can anyone see where I am going wrong?
  • dorinbogdan
    Recognized Expert Contributor
    • Feb 2007
    • 839

    #2
    Text could be a reserved word, use other var name instead, i.e. strText:
    Code:
    Intro = Replace(Intro,"'","''") 
    strText = Replace(strText,"'","''")
    
    SQL = "Insert Into Articles 
     	(AuthorId, CatId, TopstoryId, Headline, Subheadline, Intro, [Text]) 
    	Values ('" & Request("AuthorId") & "','" & 
    		     Request("CatId") & "','" & 
                               Request("TopStoryId") & "','" & 
    		     Request("Headline") & "','" & 
     		     Request("Subheadline") & "','" & 
    		     Intro & "','" & 
    	 	     strText & "')"

    Comment

    Working...