嵌套SQL语句 [英] Nested SQL Statements

查看:92
本文介绍了嵌套SQL语句的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的查询:

This my Query:

select short_name from scheme_info where sch_code in 
(SELECT '''''''' + replace(cast(Schemes as varchar(max)),''#'','''''','''''') + '''''''' FROM JM_DSS_Sets WHERE SetName = ''Institutional'') 
order by short_name



输出:



Output of:

SELECT '''''''' + replace(cast(Schemes as varchar(max)),''#'','''''','''''') + '''''''' FROM JM_DSS_Sets WHERE SetName = ''Institutional''



是:



Is:

''AG015'',''AX004'',''BB037''



如果我用上述输出替换内部sql语句,则查询工作正常.
如果我编写实际的sql语句,则查询工作正常,但没有结果.

我可以知道我要去哪里了吗?.

在此先感谢



If I replace inner sql statement with above output the query works fine.
If I write actual sql statement, the query works fine but there is no result.

May I know where I''m going wrong..??

Thanks in advance

推荐答案

我认为,如果您从内部查询输出中删除单引号,那么它将起作用

replace(cast(Schemes as varchar(max)),''#'','''''','''''')
代替
'''''''' + replace(cast(Schemes as varchar(max)),''#'','''''','''''') + ''''''''
I think if you remove the single quote marks from the inner query output then it will work
Like
replace(cast(Schemes as varchar(max)),''#'','''''','''''')
instead of
'''''''' + replace(cast(Schemes as varchar(max)),''#'','''''','''''') + ''''''''


亲爱的,如果我从内部查询中删除单引号,则输出为

Dear if i remove single quote marks from the inner query, the output is

AG015'',''AX004'',''BB037



所以IN条件变成这样



So the IN condition becomes like this

IN (AG015'',''AX004'',''BB037)



这是无效条件.

任何其他方式..?????



Which is not valid condition.

Any other way to do..??


这篇关于嵌套SQL语句的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆