SqlServer楂樼骇鐗规€?-瀛樺偍杩囩▼

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了SqlServer楂樼骇鐗规€?-瀛樺偍杩囩▼相关的知识,希望对你有一定的参考价值。

鏍囩锛?a href='http://www.mamicode.com/so/1/%e5%ad%98%e5%82%a8%e8%bf%87%e7%a8%8b' title='瀛樺偍杩囩▼'>瀛樺偍杩囩▼   add   class   code   鍙橀噺   receive   temp   end   var   

闇€姹傦細

鐢ㄦ埛闇€瑕佹彁浜ゅ姞瀵嗘暟鎹紝鎻愪氦涔嬪悗闇€瑕佽В瀵嗚繕鍘燂紝杩樺師鏈変袱绉嶇粨鏋滐細鎴愬姛鍜屽け璐ワ紒

100涓敤鎴凤紝涔嬪墠7澶╋紝鍒ゆ柇鏄惁鏈夋彁浜ゆ暟鎹紝濡傛灉鏈夋彁浜ゆ湁鏁版嵁锛屽垽鏂槸鍚﹁В瀵嗘垚鍔燂紙鍒嗗埆瀛樺湪涓や釜琛ㄤ腑锛夈€傚鏋滄病鏈夋彁浜わ紝鏄剧ず榛勮壊锛涙彁浜わ紝鏈В瀵嗘垚鍔燂紝绾㈣壊锛涙彁浜ゅ苟瑙e瘑鎴愬姛锛岀豢鑹诧紝骞舵樉绀哄搴旀椂闂淬€?/p>

鍒嗘瀽锛?/h3>

娴嬭瘯杩囬亶鍘嗘墍鏈夊崟浣嶏紝涔嬪悗閬嶅巻姣忎竴澶╋紝鍘绘煡璇㈡彁浜ゆ暟鎹紝鐒跺悗鍦ㄥ幓鏌ヨ瑙e瘑鏁版嵁銆傜粨鏋滀竴涓?00瀹跺崟浣嶏紝绔熺劧闇€瑕佸ぇ姒?-3鍒嗛挓鐨勬椂闂存潵鏌ヨ銆傦紙鎺ユ敹璁板綍閲岄潰鏁版嵁澶х害50w鏉★紝鍚庢湡鍙兘浼氭洿澶氾級锛屾槑鏄句笉鍚堥€傦紝铏界劧鍔犺繃缂撳瓨锛屼絾鏄笉绗﹀悎瑕佹眰銆?/p>

浼樺寲鎬濊矾锛?/p>

銆€銆€1. 鎴戞兂鐢?00瀹跺崟浣嶅拰7澶╁悓鏃跺幓鍏宠仈鎺ユ敹璁板綍琛紝杩涜鏌ヨ銆備篃灏辨槸澶氭潯浠跺乏澶栬繛鎺ユ煡璇€?/p>

銆€銆€2. 鎴戣鑾峰彇100瀹跺崟浣嶅拰7澶╃殑杩欐牱鐨勮〃锛岄渶瑕?00瀹跺崟浣嶅拰7涓棩鏈熺殑绗涘崱灏旂Н

銆€銆€3. 鎴戦渶瑕佷竴涓?澶╂棩鏈熺殑琛紝鍙互鍦ㄥ瓨鍌ㄨ繃绋嬩腑杩涜鍒涘缓涓存椂琛ㄣ€?/p>

鏁翠綋鎬濊矾灏辨槸杩欐牱鐨勩€?/p>

浠g爜锛?/h3>

鏁翠綋瀛樺偍杩囩▼浠g爜濡備笅锛?/p>

ALTER PROCEDURE [dbo].[AUTOTRANS]
    @xz   VARCHAR(10)=鈥?/span>410000鈥?/span> ,
    @day INT =7,
    @industryCode varchar(10)=鈥?/span>6001鈥?/span>
AS
BEGIN
    SET NOCOUNT ON;
    --瀹氫箟涓€涓彉閲忥細涓存椂琛紝鐢ㄦ埛瀛樺偍7澶╂暟鎹€?/span>
    DECLARE @days table (date date) 
    DECLARE @today date = GETDATE()
    --瀹氫箟涓€涓惊鐜紝鐢ㄤ簬鎻掑叆涔嬪墠7澶╃殑鏁版嵁锛屼粠褰撳ぉ寮€濮?/span>
    WHILE @day >= 0
    BEGIN
        insert into @days
        select DATEadd(dd,-@day, @today );
        set @day =@day-1        
    END
    --涓氬姟鍖哄煙
        SELECT D.XZ_CODE,D.UNIT_CODE,D.UNIT_NAME,    CONVERT(varchar,D.RECEIVE_TIME,108) RECEIVE_TIME,
            CONVERT(varchar,MAX (E.RESTORE_TIME),108) RESTORE_TIME,D.date SELECT_DATE
        FROM (
        SELECT A.XZ_CODE,A.UNIT_CODE,A.UNIT_NAME,MAX(C.RECEIVE_TIME) RECEIVE_TIME,B.date FROM 
        (SELECT XZ_CODE,UNIT_CODE,UNIT_NAME
        FROM T_UNIT_AUDIT WHERE XZ_CODE = @xz AND INDUSTRY_CODE = @industryCode
        ) A CROSS JOIN @days B
        LEFT JOIN T_FILE_RECEIVE_RECORD C ON A.UNIT_CODE = C.UNIT_CODE AND A.XZ_CODE = C.XZ_CODE 
        AND CONVERT(VARCHAR,B.date,23) = CONVERT(VARCHAR,C.RECEIVE_TIME,23)
        GROUP BY A.XZ_CODE,A.UNIT_CODE,A.UNIT_NAME,B.date
        ) D LEFT JOIN T_FILE_RESTORE_RECORD E ON D.XZ_CODE = E.XZ_CODE AND D.UNIT_CODE = E.UNIT_CODE 
            AND CONVERT(VARCHAR,D.RECEIVE_TIME,23) = CONVERT(VARCHAR,E.RESTORE_TIME,23)
        GROUP BY D.RECEIVE_TIME,D.XZ_CODE,D.UNIT_CODE,D.UNIT_NAME,D.date
END

 缁撴灉娴嬭瘯锛?/h3>

鐩墠锛岄拡瀵?00瀹跺崟浣?澶╃殑鏁版嵁锛屽彲浠ヤ繚璇佸ぇ绾?绉掑唴瀹屾垚鏌ヨ锛屽綋鐒惰繖杩樺寘鍚簡鎴戝湪鍚庢湡杩涜鏁版嵁澶勭悊鐨勬椂闂淬€?/p>

鍐欏湪鏈€鍚庯細

鐢变簬椤圭洰鏄娇鐢ㄧ殑jdbcTemplate杩涜鐨勬寔涔呭眰鎿嶄綔锛屾墍浠ユ寔涔呭眰鎿嶄綔浠g爜闄勪笂锛?/p>

    public List<Map<String, Object>> autoTrans(Map<String, Object> param) {
        String sql = "{call AUTOTRANS(?,?,?)} ";  //璋冪敤瀛樺偍杩囩▼
        List<Map<String, Object>> resultList = jdbcTemplate.execute(
        //瀹氫箟浼犲叆鍙傛暟锛岃繑鍥瀞tatement
                (connection)->{
                 CallableStatement statement = connection.prepareCall(sql);
銆€銆€銆€銆€銆€銆€銆€銆€銆€銆€statement.setString(1,param.get("xzCode").toString());
銆€銆€銆€銆€銆€銆€銆€銆€銆€銆€statement.setString(2,param.get("days").toString());
銆€銆€銆€銆€銆€銆€銆€銆€銆€銆€statement.setString(3,param.get("industryCode").toString());
                        return statement;
                },
         //鎵ц瀛樺偍杩囩▼锛屾嬁鍒扮粨鏋滈泦锛屽鐞嗙粨鏋滈泦銆傚洜涓鸿繖閲宭ambda琛ㄨ揪寮忓鏋滀笉璁剧疆鍙傛暟绫诲瀷浼氬鑷撮噸澶嶏紝灏辫缃簡鍙傛暟绫诲瀷
                (CallableStatement callableStatement) -> {
                        List<Map<String,Object>> resultListParam =new ArrayList<>();
                        callableStatement.execute();
                        ResultSet resultSet = callableStatement.getResultSet();
                        while (resultSet.next()){
                            Map<String,Object> result = new HashMap<>();                         
銆€銆€銆€銆€銆€銆€銆€銆€銆€銆€銆€銆€銆€銆€銆€銆€result.put("xzCode",resultSet.getString("XZ_CODE"));
銆€銆€銆€銆€銆€銆€銆€銆€銆€銆€銆€銆€銆€銆€銆€銆€result.put("unitCode",resultSet.getString("UNIT_CODE"));
銆€銆€銆€銆€銆€銆€銆€銆€銆€銆€銆€銆€銆€銆€銆€銆€result.put("unitName",resultSet.getString("UNIT_NAME"));
銆€銆€銆€銆€銆€銆€銆€銆€銆€銆€銆€銆€銆€銆€銆€銆€result.put("receiveTime",resultSet.getString("RECEIVE_TIME"));
銆€銆€銆€銆€銆€銆€銆€銆€銆€銆€銆€銆€銆€銆€銆€銆€result.put("restoreTime",resultSet.getString("RESTORE_TIME"));
銆€銆€銆€銆€銆€銆€銆€銆€銆€銆€銆€銆€銆€銆€銆€銆€result.put("selectDate",resultSet.getDate("SELECT_DATE")); resultListParam.add(result); } return resultListParam; }); return resultList; }

鍒版缁撴潫锛屾湰娆℃煡璇紭鍖栧畬鎴愶紝鍩烘湰杈惧埌鐩爣瑕佹眰銆?/p>







以上是关于SqlServer楂樼骇鐗规€?-瀛樺偍杩囩▼的主要内容,如果未能解决你的问题,请参考以下文章

DNS鍩熷悕瑙f瀽杩囩▼

闃舵1 璇█鍩虹+楂樼骇_1-3-Java璇█楂樼骇_02-缁ф壙涓庡鎬乢绗?鑺?鎶借薄绫籣19-鍙戠孩鍖呮渚媉瀹炵幇

楂樼骇鎸囦护

鈥滃垎甯冨紡瀛樺偍鎶€鏈€濇垨灏嗘垚涓轰腑鍥界鎶€鑵鹃鐨勪笅涓€涓敮鐐癸紝IPFS/FIL鍗冲皢杩庢潵澶х垎鍙戯紒

Kubernetes 瀛︿範21 kubernetes楂樼骇璋冨害鏂瑰紡