22,209
社区成员
发帖
与我相关
我的任务
分享
select sDish_c into #sdish from Cysy_nDoc (nolock) where sDish_c=@sDish_c and substring(sDoc_c,0,7)=@month
and @side=@sIde and sTrade_c between @sTrade_cb and @sTrade_ce and nStatus <>'X'
--上面 是你写的插入临时表的语句
--再看下面:用select出来的表中只有一列,而下面的语句你要查好多列,所以错误
set a1=(select count(sDish_c) from #sdish (nolock) where sDish_c=@sDish_c and substring(sDoc_c,0,9)=@month+'01'
and side=@sIde and sTrade_c between @sTrade_cb and @sTrade_ce and nStatus <>'X')
SQL Select语句完整的执行顺序:
1、from子句组装来自不同数据源的数据;
2、where子句基于指定的条件对记录行进行筛选;
3、group by子句将数据划分为多个分组;
4、使用聚集函数进行计算;
5、使用having子句筛选分组;
6、计算所有的表达式;
7、使用order by对结果集进行排序。
(8) SELECT (9) DISTINCT (11) <TOP_specification> <select_list>
(1) FROM <left_table>
(3) <join_type> JOIN <right_table>
(2) ON <join_condition>
(4) WHERE <where_condition>
(5) GROUP BY <group_by_list>
(6) WITH {CUBE | ROLLUP}
(7) HAVING <having_condition>
(10) ORDER BY <order_by_list>