You can find details in the SQL Server Books Online:
<Excerpt href="tsqlref.chm::/ts_ca-co_1n1v.htm">
If a character string enclosed in single quotation marks contains an
embedded quotation mark, represent the embedded single quotation mark with
two single quotation marks.
</Excerpt>
Another method is to use parameters rather than building a query string so
that you don't need to escape the quotes. Example below. Also, consider
using a login other than 'sa' for application database access.
Function Main()
Const adVarChar = 200
Const adParamInput = 1
Dim ADOcon
Dim ADOcmd
Dim ADOparm
Dim strConnection
Dim ADOrst
Dim strSQL1
Dim CurName
Dim CurDesc
Set ADOcon = CreateObject("ADODB.Connection")
Set ADOcmd = CreateObject("ADODB.Command")
ADOcon.Provider = "sqloledb"
ADOcon.Properties("Data Source").Value = "(local)"
ADOcon.Properties("Initial Catalog").Value ="AATest"
ADOcon.Properties("User ID").Value ="MyLogin"
ADOcon.Properties("Password").Value ="MyPassword"
ADOcon.Open strConnection
CurName= "7' Test "
CurDesc = "Whatever "
ADOcmd.ActiveConnection = ADOcon
ADOcmd.CommandText = "INSERT INTO TableTest (TestName, TestDesc) VALUES ( ?,
? )"
Set ADOparm = ADOcmd.CreateParameter("TestName", adVarChar, adParamInput,
20, CurName)
ADOcmd.Parameters.Append ADOparm
Set ADOparm = ADOcmd.CreateParameter("TestDesc", adVarChar, adParamInput,
20, CurDesc)
ADOcmd.Parameters.Append ADOparm
ADOcmd.Execute
Main = DTSTaskExecResult_Success
End Function
--
Hope this helps.
Dan Guzman
SQL Server MVP
[quoted text, click to view] "robc" <rwc1960@bellsouth.net> wrote in message
news:oOVDb.11286$lh6.7086@bignews4.bellsouth.net...
> Thanks, works great now. I do not understand why though... if time
> permits, could you please point me in the direction of some helpful
> documentation.
>
> Thanks,
> Rob
>
>
> "Dan Guzman" <danguzman@nospam-earthlink.net> wrote in message
> news:%23LlPf4ExDHA.1088@tk2msftngp13.phx.gbl...
> > You can replace the quote with 2 consecutive quotes. For example:
> >
> > strSQL1 = "INSERT INTO TableTest (TestName, TestDesc) VALUES ( '"
> > &DoubleUpQuotes(CurName)& "','" &DoubleUpQuotes(CurDesc)& "')"
> >
> > Function DoubleUpQuotes(Value)
> > DoubleUpQuotes = Replace(Value, "'", "''")
> > End Function
> >
> > --
> > Hope this helps.
> >
> > Dan Guzman
> > SQL Server MVP
> >
> > "robc" <rwc1960@bellsouth.net> wrote in message
> > news:jRPDb.7152$3B2.4290@bignews1.bellsouth.net...
> > > Running a DTS package that has worked until now... delimiters are now
> > > present in the data and the package crashes... anyone know how to
> prevent
> > ?
> > > I've attached snippets of the code so you could reproduce the error if
> > > necessary. I believe I must reconstruct strSQL1, but how ?
> > >
> > >
> > >
> > > -- The table it tries to insert into
> > > if exists (select * from dbo.sysobjects where id =
> > > object_id(N'[dbo].[TableTest]') and OBJECTPROPERTY(id, N'IsUserTable')
=
> > 1)
> > > drop table [dbo].[TableTest]
> > > GO
> > >
> > > CREATE TABLE [dbo].[TableTest] (
> > > [TestName] [char] (30) NULL ,
> > > [TestDesc] [char] (30) NULL
> > > ) ON [PRIMARY]
> > > GO
> > >
> > >
> > >
> > >
'**********************************************************************
> > > ' Visual Basic ActiveX Script
> > >
> '************************************************************************
> > >
> > > Function Main()
> > >
> > >
> > > Dim ADOcon
> > > Dim strConnection
> > > Dim ADOrst
> > > Dim strSQL1
> > > Dim CurName
> > > Dim CurDesc
> > >
> > > Set ADOcon = CreateObject("ADODB.Connection")
> > > Set ADOrst = CreateObject("ADODB.Recordset")
> > > ADOcon.Provider = "sqloledb"
> > > ADOcon.Properties("Data Source").Value = "(local)"
> > > ADOcon.Properties("Initial Catalog").Value ="AATest"
> > > ADOcon.Properties("User ID").Value ="sa"
> > > ADOcon.Properties("Password").Value ="sa"
> > >
> > > ADOcon.Open strConnection
> > >
> > > CurName= "7' Test "
> > > CurDesc = "Whatever "
> > >
> > > strSQL1 = "INSERT INTO TableTest (TestName, TestDesc) VALUES ( '"
> > > &CurName& "','" &CurDesc& "')"
> > > 'You can plainly see why it crashes here
> > > msgbox strSQL1
> > > ADOcon.Execute strSQL1
> > >
> > >
> > > Main = DTSTaskExecResult_Success
> > > End Function
> > >
> > >
> >
> >
>
>