sql查询问题

时间:2010-03-25 09:39:36

标签: c# sql

插入[任务]                ([登录名]                ,[类型]                ,[过滤]                ,[字典]                [描述])

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]是我需要在我的服务器上运行的查询的一部分。

我明白了:

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

如何修复这个错误?

2 个答案:

答案 0 :(得分:4)

这是因为你在一个值中有撇号。具体来说,你的过滤字符串中包含撇号,需要通过将它们加倍来进行转义:

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

答案 1 :(得分:1)

有点不清楚你正在尝试做什么,在面值上你试图将where子句的一部分插入到表中。

正在追捕你的是('TN'),因为该部分中的引号结束了外部引号。试试(''TN'')