`
sjk2013
  • 浏览: 2190130 次
文章分类
社区版块
存档分类
最新评论

Subqueries are not allowed in this context. Only scalar expressions are allowed.

 
阅读更多

我想获取表中某一列的最大值,然后插入到另外一个表中,报错的Sql如下:

insert into AA(AA_ID,AA_YWFSRQ) 
values
(NewID(),(  SELECT   CONVERT(varchar, DATEADD(day,- 1, CAST(SUBSTRING(MAX(YEB_RQ), 1, 4) 
                                    + SUBSTRING(MAX(YEB_RQ), 5, 2) + SUBSTRING(MAX(YEB_RQ), 7, 2) 
                                     AS datetime)), 112) FROM      YEB ));
修正:

insert into AA(AA_ID,AA_YWFSRQ) 
select
NewID(),(  SELECT   CONVERT(varchar, DATEADD(day,- 1, CAST(SUBSTRING(MAX(YEB_RQ), 1, 4) 
                                    + SUBSTRING(MAX(YEB_RQ), 5, 2) + SUBSTRING(MAX(YEB_RQ), 7, 2) 
                                     AS datetime)), 112) FROM      YEB )
错误提示信息:
Subqueries are not allowed in this context. Only scalar expressions are allowed.

==》在此上下文中不允许使用子查询。只允许使用标量表达式。

分享到:
评论

相关推荐

    Sql for mysql

    1.10 The Structure of This Book . . . . . . . . . . . . . . . . . . . . . . . . . . . 27 CHAPTER 2 The Tennis Club Sample Database . . . . . . . . . . . . . . . . 29 2.1 Introduction . . . . . . . . ....

    hibernate3.6 文档(pdf 格式)

    截至 2011-08-29 官方公布的最新 hibernate 文档,此为英文版,配套中文版下载地址:http://download.csdn.net/source/3557584。 详细信息: 版本:3.6.3.Final,作者:Gavin King, Christian Bauer, Max Rydahl ...

    Pro Core Data for iOS.pdf

    251 ■ Chapter 9: Using Core Data in Advanced Applications.....................................................................283 ■ Index:..............................................................

    Doctrine ORM for PHP.pdf

    Table of Contents Introduction....................................................................................................13 Code Examples.........................................................

    微软内部资料-SQL性能优化5

    Normally, only the columns in the WHERE clause are helpful in determining useful indexes, but for a covering index, all columns must be included. If all columns needed for the query are in the index,...

    Hibernate Reference Documentation3.1

    3.8.3. Current Session context management with JTA 3.8.4. JMX deployment 4. Persistent Classes 4.1. A simple POJO example 4.1.1. Implement a no-argument constructor 4.1.2. Provide an identifier ...

    MySql存储过程编程.chm

    What This Book Does Not Cover Conventions Used in This Book Which Version? Resources Available at the Book's Web Site Using Code Examples Safari® Enabled How to Contact Us ...

    Inside Microsoft SQL Server 2000

    Security and the User Context . Licensing . Network Protocols . Collation . Multiple Instances . Installing SQL Server . Basic Configuration After Installation . Remote and Unattended ...

    MariaDB and MySQL Common Table Expressions and Window Functions Revealed

    Avoid writing queries that are a difficult-to-maintain quagmire of self-joins and nested subqueries Recognize situations that call for window functions, and learn when to use these features Reduce the...

    Murach's MySQL(第二版)

    When he's not programming or writing books about programming, he can be found surfing or writing music. "If you ever wanted to learn to use MySQL, write SQL queries, create database elements, then ...

    Murach s MySQL(2ed,2015)

    “If you ever wanted to learn to use MySQL, write SQL queries, create database elements, then this is the book to pick up.” (JavaRanch.com) “I was amazed at how much information was packed into ...

    SQLAlchemy Documentation

    Selecting Entities from Subqueries . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27 Using EXISTS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ...

    SQL.and.Relational.Theory.How.to.Write.Accurate.SQL.Code.3rd.Edition

    Topics whose treatment has been expanded include data types and domains, table comparisons, image relations, aggregate operators and summarization, view updating, and subqueries. A special feature of...

    hadoop_the_definitive_guide_3nd_edition

    What’s Covered in this Book 14 Compatibility 15 2. MapReduce . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17 A Weather Dataset...

    expert_t_sql_window_functions_in_sql_server.pdf

    Window functions do not let you do anything that was impossible to do with earlier functionality, and they have nothing to do with the Microsoft Windows API. Using previously available methods, such ...

    The.Language.of.SQL.2nd.Edition.0134658256

    Many SQL texts attempt to serve as an encyclopedic reference on SQL syntax -- an approach that is often counterproductive, because that information is readily available in online references published ...

    The Language of SQL(Addison,2ed,2016)

    Many SQL texts attempt to serve as an encyclopedic reference on SQL syntax — an approach that is often counterproductive, because that information is readily available in online references published ...

    数据库技术与Oracle:sql-06 Subqueries.ppt

    数据库技术与Oracle:sql-06 Subqueries.ppt

Global site tag (gtag.js) - Google Analytics