zoukankan      html  css  js  c++  java
  • 几个小嵌套

    update TB_AssetsInfo set UseType=0 where
    AssetsName='204室'

    select * from TB_AssetsInfo where AssetsName='204室'

    一条一条更新会死人的!

    --更新符合条件的记录

    update TB_AssetsInfo set UseType=0 where infoId in(

    --找出符合条件记录的ID【zcId就是InfoId】
    select zcId from(

    --找出符合条件的记录

    select * from (

    --视图

    SELECT     InfoId AS zcId, UseType, AssetsLevel, AssetsName,

    --转换一下显示状态

    (CASE WHEN UseType = 1 THEN '已租' WHEN UseType = 0 THEN '未租' END) AS UseTypeName,

    AssetsNum,
                          CateCode, InfoOrder, ISNULL
                              ((SELECT     dbo.TB_Customer.khName
                                  FROM         dbo.TB_Customer INNER JOIN
                                                        dbo.TB_Contract ON dbo.TB_Customer.khId = dbo.TB_Contract.khId
                                  WHERE     (dbo.TB_Contract.htId =
                                                            (SELECT     TOP (1) htId
                                                              FROM          dbo.TB_Contract
                                                              WHERE      (htIsEnd = 0) AND (htId IN
                                                                                         (SELECT     htId
                                                                                           FROM          dbo.TB_Contract_Assets
                                                                                           WHERE      (zcId = dbo.TB_AssetsInfo.InfoId)))))), '') AS CustomName, ISNULL
                              ((SELECT     dbo.TB_Contract.htCode
                                  FROM         dbo.TB_Customer INNER JOIN
                                                        dbo.TB_Contract ON dbo.TB_Customer.khId = dbo.TB_Contract.khId
                                  WHERE     (dbo.TB_Contract.htId =
                                                            (SELECT     TOP (1) htId
                                                              FROM          dbo.TB_Contract
                                                              WHERE      (htIsEnd = 0) AND (htId IN
                                                                                         (SELECT     htId
                                                                                           FROM          dbo.TB_Contract_Assets
                                                                                           WHERE      (zcId = dbo.TB_AssetsInfo.InfoId)))))), '') AS htCode
    FROM         dbo.TB_AssetsInfo) as aa
    where UseTypeName='已租' and CustomName='') as qq)

  • 相关阅读:
    Ubuntu16.04 安装Teamviewer
    Redis 中的事务
    apache rewrite .htaccess 站点内容重定向实例
    PHP_EOL常量
    PHP 设计模式之适配器模式
    MYSQL优化
    php设计模式之简单工厂模式
    php设计模式之单例模式
    PHP设计模式之策略模式
    PHP 设计模式之观察者模式 (转载)
  • 原文地址:https://www.cnblogs.com/howie/p/2487343.html
Copyright © 2011-2022 走看看