tags:

views:

53

answers:

2

Hi, I've got query:

INSERT INTO [Tasks]
           ([LoginName]
           ,[Type]
           ,[Filter]
           ,[Dictionary]
           ,[Description])

Select N'Anonymous',4,'SomeTable.targetcode in (select Code from cities where countrycode in ('TN')) and SomeTable.SomeValue in ('13','15')',3,N'Cities from tunis'
Union All
...

[Dictionary] is a part of query that i need to function on my server.

I get:

Incorrect syntax near ')) and SomeTable.SomeValue in (13,15)'.

How to repair this mistake ??

+4  A: 

It's because you have apostrophes within a value. Specifically, your filter string includes apostrophes in it, which need to be escaped by doubling them up:

INSERT INTO [Tasks]
       ([LoginName]
       ,[Type]
       ,[Filter]
       ,[Dictionary]
       ,[Description])

Select N'Anonymous',4,'SomeTable.targetcode in (select Code from cities where countrycode in (''TN'')) and SomeTable.SomeValue in (''13'',''15'')',3,N'Cities from tunis'
Union All

HTH,
Kent

Kent Boogaart
+1  A: 

It's a bit unclear exactly what you are trying to do, on face value you are trying to insert a part of a where clause into the table.

What is catching you out is the in ('TN') because the quotes within that part are ending the outer quotes. Try (''TN'')

Andrew