The SQL implementation, if present, is updated, and if it does not exist, add

Source: Internet
Author: User

Alter procproc_datasummary asbegin    beginTrybegin Tran            --PV            --statistical information deposited in temporary tables            SelectShareduserid,platformid,CONVERT(varchar( -), CreateDate,111) asCreatdate,channelid,sharedmanagerid,COUNT(*) asQty into#PVData fromDbo. PvinfowhereSharedlevel=1 Group  byShareduserid,platformid,channelid,sharedmanagerid,CONVERT(varchar( -), CreateDate,111)            --Update will count the information that exists            UpdateDbo. DatasummarySetPV=dbo. #PVData. Qty from#PVDatawhereDbo. Datasummary.userid=dbo. #PVData. Shareduserid andDbo. Datasummary.platformid=dbo. #PVData. PlatformID andDbo. Datasummary.channelid=dbo. #PVData. Channelid andDbo. Datasummary.managerid=dbo. #PVData. Sharedmanagerid andDbo. Datasummary.summarydate=dbo. #PVData. Creatdate--Statistics of new PV information            Insert  intodbo. DatasummarySelectShareduserid,platformid,creatdate,channelid,sharedmanagerid,qty,0,0,0,0,0,0,GETDATE() fromdbo. #PVData awhere  not exists(Select *  fromDbo. DatasummarywhereDbo. Datasummary.userid=A.shareduserid andDbo. Datasummary.platformid=A.platformid andDbo. Datasummary.channelid=A.channelid andDbo. Datasummary.managerid=A.sharedmanagerid andDbo. Datasummary.summarydate=a.creatdate)--UV            --statistical information deposited in temporary tables            SelectShareduserid,platformid,CONVERT(varchar( -), CreateDate,111) asCreatdate,channelid,sharedmanagerid,COUNT(*) asQty into#UVData fromDbo. UvinfowhereSharedlevel=1 Group  byShareduserid,platformid,channelid,sharedmanagerid,CONVERT(varchar( -), CreateDate,111)            --Update will count the information that exists            UpdateDbo. DatasummarySetUv=dbo. #UVData. Qty from#UVDatawhereDbo. Datasummary.userid=dbo. #UVData. Shareduserid andDbo. Datasummary.platformid=dbo. #UVData. PlatformID andDbo. Datasummary.channelid=dbo. #UVData. Channelid andDbo. Datasummary.managerid=dbo. #UVData. Sharedmanagerid andDbo. Datasummary.summarydate=dbo. #UVData. Creatdate--statistics of new UV information            Insert  intodbo. DatasummarySelectShareduserid,platformid,creatdate,channelid,sharedmanagerid,qty,0,0,0,0,0,0,GETDATE() fromdbo. #UVData awhere  not exists(Select *  fromDbo. DatasummarywhereDbo. Datasummary.userid=A.shareduserid andDbo. Datasummary.platformid=A.platformid andDbo. Datasummary.channelid=A.channelid andDbo. Datasummary.managerid=A.sharedmanagerid andDbo. Datasummary.summarydate=a.creatdate)Commit Tran    EndTrybeginCatchrollback Tran    EndCatchEnd

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.