2017-03-07 20 views
1

参数我想写在Microsoft SQL Server SQL查询的类型PyQt的似乎是用于SQL Lite或MySQL数据库。我如何为Microsoft SQL做这件事?PyQt的:在线</p> <pre><code>list=['Engineer', 'Doctor', 'Lawyer'] select * from Occupations where OccupationName in (list) </code></pre> <p>我已阅读各种职位,但他们:用一个字符串列表作为一个MS SQL查询

此外,在MS SQL中,字符串值需要用双引号引起来,而不是在列表项中使用单引号。我将如何做到这一点?

回答

0

这个主题应该可以帮到你! T-SQL split string

BTW: 你可以写你在PARAMS CTE:

;with list as (
    select 'Engineer' as [occupation] union 
    select 'Doctor' union 
    select 'Lawyer' 
) 
select * from Occupations where OccupationName in (select occupationfrom from list) 

或像这样很简单:

select * from Occupations where OccupationName in ('Engineer', 'Doctor', 'Lawyer') 
+0

@dmitrycat喜:这只是一个例子,产生我的实际列表用户从检查列表中选择选项后。所以,我需要运行一个查询,无论用户检查,所以它必须是动态的 – Sarah

+0

我明白了一些后,http://stackoverflow.com/questions/10914576/t-sql-split-string我想这是什么你需要 –

相关问题