员工薪资历史-Union实现
( 2010-8-27 记录)员工薪资历史 -Union 实现: 1、 表结构 Salary ( id , empID , jbxz,yfxz,sfxz,jse , pid ) Perion(id,bm,year,month,sdate,edate) 表结构大体是这样的,其中 bm 是薪资日期编码如 2010-8 ,但是不一定也可以是 108 ,无规则可言。
( 2010-8-27 记录)员工薪资历史 -Union 实现:
1、 表结构
Salary ( id , empID , jbxz,yfxz,sfxz,jse , pid )
Perion(id,bm,year,month,sdate,edate…)
表结构大体是这样的,其中 bm 是薪资日期编码如 2010-8 ,但是不一定也可以是 108 ,无规则可言。 Year 是薪资年, month 是薪资月, sdate 和 edate 是开始和结束日期。
2. 本来打算用交叉表实现的,原本已经用交叉表实现了,不过最后未能用交叉表实现“ xxxx 小计”,只能实现的显示“小计”,最后改用union 方式实现。
3. 实现要点:
注意 group by 中的字段及顺序,注意 order by 中的字段及顺序
4 .代码如下:
/** 统计员工的期间薪资 */ IF EXISTS (select * from sysobjects where id = object_id('sp_count_salary') and OBJECTPROPERTY(id, N'IsProcedure') = 1) DROP PROCEDURE sp_count_salary GO CREATE PROCEDURE sp_count_salary @P_EMP_ID INT, --员工id @P_SPLA_PER_ID INT, --开始期间id @P_EPLA_PER_ID INT --结束期间id WITH encryption AS BEGIN BEGIN TRANSACTION T1 DECLARE @V_S_YEAR INT --开始期间年份 DECLARE @V_S_MONTH INT --开始期间月份 DECLARE @V_E_YEAR INT --结束期间年份 DECLARE @V_E_MONTH INT --结束期间月份 select @V_S_YEAR=pla_per_year,@V_S_MONTH=pla_per_month from pla_period where pla_per_id=@P_SPLA_PER_ID select @V_E_YEAR=pla_per_year,@V_E_MONTH=pla_per_month from pla_period where pla_per_id=@P_EPLA_PER_ID select (CAST(pla_per_year AS NVARCHAR(4)) + '-' + RIGHT('0' + CAST(pla_per_month AS NVARCHAR(2)), 2)) as '时间', sum(pay_res_btax) N'基本薪资',sum(pay_res_atax) N'应发薪资',sum(pay_res_result) N'实发薪资',sum(pay_res_tax) N'缴税额' from pla_period pp,pay_res pr where pp.pla_per_id = pr.pay_res_perid and pay_res_empid = @P_EMP_ID and (pla_per_year > @V_S_YEAR or (pla_per_year = @V_S_YEAR and pla_per_month >= @V_S_MONTH)) and (pla_per_year < @V_E_YEAR or (pla_per_year = @V_E_YEAR and pla_per_month <= @V_E_MONTH)) group by pla_per_year,pla_per_month union ( select cast(pla_per_year as varchar(10))+N'小计' as '时间', sum(pay_res_btax) N'基本薪资',sum(pay_res_atax) N'应发薪资',sum(pay_res_result) N'实发薪资',sum(pay_res_tax) N'缴税额' from pla_period pp,pay_res pr where pp.pla_per_id = pr.pay_res_perid and pay_res_empid = @P_EMP_ID and (pla_per_year > @V_S_YEAR or (pla_per_year = @V_S_YEAR and pla_per_month >= @V_S_MONTH)) and (pla_per_year < @V_E_YEAR or (pla_per_year = @V_E_YEAR and pla_per_month <= @V_E_MONTH)) group by pla_per_year ) union ( select N'合计' as '时间', sum(pay_res_btax) N'基本薪资',sum(pay_res_atax) N'应发薪资',sum(pay_res_result) N'实发薪资',sum(pay_res_tax) N'缴税额' from pla_period pp,pay_res pr where pp.pla_per_id = pr.pay_res_perid and pay_res_empid = @P_EMP_ID and (pla_per_year > @V_S_YEAR or (pla_per_year = @V_S_YEAR and pla_per_month >= @V_S_MONTH)) and (pla_per_year < @V_E_YEAR or (pla_per_year = @V_E_YEAR and pla_per_month <= @V_E_MONTH)) ) order by (CAST(pla_per_year AS NVARCHAR(4)) + '-' + RIGHT('0' + CAST(pla_per_month AS NVARCHAR(2)), 2)) IF @@ERROR > 0 BEGIN ROLLBACK TRANSACTION T1 END ELSE BEGIN COMMIT TRANSACTION T1 END END GO --EXEC sp_count_salary 4901,1131,1153

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



Are you looking for the five lighthouses in the History of the Sinking Tide quest? This guide will give you a detailed explanation of where these lighthouses are waiting to be discovered. We hope this will help you find the lighthouse you need quickly and complete your mission successfully! The history of the sinking of the Mingtide Five lighthouse locations are introduced and the specific locations are listed: 1. The first lighthouse: Please go to the barren stone highland, located directly above Beiluoye. 2. The second lighthouse: Next, please go to the Zhongqu Platform, which can be found around the teleportation point on the northeast side. 3. The third lighthouse: Please go to the southeast of Hukou Mountains and find it along Wuming Bay. 4. The fourth lighthouse: Please go to the teleportation point at the southeastern end of the Angry Birds Zee, near the cliff. 5. The fifth lighthouse: Please go to the first silent zone of the Lightless Forest, and you will find it on the edge of the cliff.

How to implement dual WeChat login on Huawei mobile phones? With the rise of social media, WeChat has become one of the indispensable communication tools in people's daily lives. However, many people may encounter a problem: logging into multiple WeChat accounts at the same time on the same mobile phone. For Huawei mobile phone users, it is not difficult to achieve dual WeChat login. This article will introduce how to achieve dual WeChat login on Huawei mobile phones. First of all, the EMUI system that comes with Huawei mobile phones provides a very convenient function - dual application opening. Through the application dual opening function, users can simultaneously

The programming language PHP is a powerful tool for web development, capable of supporting a variety of different programming logics and algorithms. Among them, implementing the Fibonacci sequence is a common and classic programming problem. In this article, we will introduce how to use the PHP programming language to implement the Fibonacci sequence, and attach specific code examples. The Fibonacci sequence is a mathematical sequence defined as follows: the first and second elements of the sequence are 1, and starting from the third element, the value of each element is equal to the sum of the previous two elements. The first few elements of the sequence

How to implement the WeChat clone function on Huawei mobile phones With the popularity of social software and people's increasing emphasis on privacy and security, the WeChat clone function has gradually become the focus of people's attention. The WeChat clone function can help users log in to multiple WeChat accounts on the same mobile phone at the same time, making it easier to manage and use. It is not difficult to implement the WeChat clone function on Huawei mobile phones. You only need to follow the following steps. Step 1: Make sure that the mobile phone system version and WeChat version meet the requirements. First, make sure that your Huawei mobile phone system version has been updated to the latest version, as well as the WeChat App.

The Go language was developed by Google. It was originally conceived in 2007 and version 1.0 was released in 2012. Its key milestones include: 2012: Go 1.0 is released, introducing concurrency, memory safety and garbage collection. 2020: Go2 is released, introducing modularity, coroutine improvements, and support for generics and error handling. 2022: Go 1.19 is released, providing performance optimization and support for generic types and functions.

In today's software development field, Golang (Go language), as an efficient, concise and highly concurrency programming language, is increasingly favored by developers. Its rich standard library and efficient concurrency features make it a high-profile choice in the field of game development. This article will explore how to use Golang for game development and demonstrate its powerful possibilities through specific code examples. 1. Golang’s advantages in game development. As a statically typed language, Golang is used in building large-scale game systems.

Implementing exact division operations in Golang is a common need, especially in scenarios involving financial calculations or other scenarios that require high-precision calculations. Golang's built-in division operator "/" is calculated for floating point numbers, and sometimes there is a problem of precision loss. In order to solve this problem, we can use third-party libraries or custom functions to implement exact division operations. A common approach is to use the Rat type from the math/big package, which provides a representation of fractions and can be used to implement exact division operations.

PHP Game Requirements Implementation Guide With the popularity and development of the Internet, the web game market is becoming more and more popular. Many developers hope to use the PHP language to develop their own web games, and implementing game requirements is a key step. This article will introduce how to use PHP language to implement common game requirements and provide specific code examples. 1. Create game characters In web games, game characters are a very important element. We need to define the attributes of the game character, such as name, level, experience value, etc., and provide methods to operate these
