Sql server 2005 如何摆脱SQL Server中的#temp表和CTE
因此,我问了一个关于如何摆脱临时表的问题 也下定决心了。。但我也不想用CTE 任何想法,如何将所有这些查询合并为一个Sql server 2005 如何摆脱SQL Server中的#temp表和CTE,sql-server-2005,left-join,common-table-expression,Sql Server 2005,Left Join,Common Table Expression,因此,我问了一个关于如何摆脱临时表的问题 也下定决心了。。但我也不想用CTE 任何想法,如何将所有这些查询合并为一个 select {some columns} into #temp1 from {some tables} where {conditions1} select {some other columns} into #temp2 from {some tables} where {conditions2} select {some other columns} into #temp
select {some columns} into #temp1 from {some tables} where {conditions1}
select {some other columns} into #temp2 from {some tables} where {conditions2}
select {some other columns} into #temp3 from {some tables} where {conditions3}
select {some columns from all #temp tables} from #temp1, #temp2,
#temp3 where {conditions}
谢谢
Jai我完全不清楚您想要实现什么,但是如果您不想使用CTE(无论出于什么奇怪的原因),派生表可能会实现您想要的功能:
select {some columns
from (
select {some columns}
from {some tables}
where {conditions1}
) as t1
join (
select {some other columns}
from {some tables}
where {conditions2}
) as t2 ON {join condition between t1 and t2}
join (
select {some other columns}
from {some tables}
where {conditions3}
) as t3 ON {join condition between t2 and t3}
where {conditions}
(虽然在技术上没有真正的区别,但这只是编写相同内容的一种不同方式)如果没有表脚本、所需的列、WHERE和JOIN条件,我们就不能help@gbn,完全同意…但我不能在这里发布我的疑问。谢谢,事实上,我已经解决了…但是我在同一个问题上遇到了一些其他的例外。你是对的…这只是写CTE东西的另一种方式…但是我想,我也不能用这个…我想为同样的问题写一个查询。