Problem with sql 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 re开发者_Python百科pair this mistake ??
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
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'')
精彩评论