开发者

Problem with sql query

开发者 https://www.devze.com 2022-12-24 19:39 出处:网络
INSERT INTO [Tasks] ([LoginName] ,[Type] ,[Filter] ,[Dictionary] ,[Description]) Select N\'Anonymous\',4,\'SomeTable.targetcode in (select Code from cities where countrycode in (\'TN\')) and SomeTabl

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'')

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号