DB2对年份的处理Year()
public DataSet GetCustomerAllocListByQC(CustomerAllocQueryDataContract aQC)
{
StringBuilder sql = new StringBuilder();
sql.Append(@"SELECT * FROM
(SELECT
'01' AS CUSTOMERALLOCTYPE,'新车客户' AS CUSTOMERALLOCTYPENAME,
CASE WHEN T1.CUSTOMERGRADE = 'A' THEN 'A'
WHEN T1.CUSTOMERGRADE = 'B' THEN 'B'
WHEN T1.CUSTOMERGRADE = 'C' THEN 'C'
WHEN T1.CUSTOMERGRADE = 'D' THEN 'D'
WHEN T1.CUSTOMERGRADE IS NULL THEN 'D' END AS CUSTOMERGRADE,
T4.CUSTOMERCODE,T4.CUSTOMERNAME,
T4.MOBILEPHONE,T4.MOBILEPHONE1,T4.TELEPHONE,
CASE WHEN T4.SEX = 'F' THEN '?' WHEN T4.SEX = 'M' THEN '?' END AS SEX,
T4.PROFESSIONCODE,T5.COMMONNAME AS PROFESSIONNAME,
T2.CARLICENSENO,T2.FRAMENO,T2.CARMODELPKID,
T8.COMMONNAME AS INSURERNAME, T6.INSURERCODE , T6.INSURANCEBUYDATE, T6.INSURANCEMATURITYDATE
,T3.ORIGINALSALEID,T7.FULLNAME AS ORIGINALSALENAME
,T3.ISALLOC
FROM RM_CARINFO T1
LEFT JOIN VM_CARINFO T2 ON T1.FRAMENO = T2.FRAMENO
LEFT JOIN RT_CARALLOCINFO T3 ON T1.FRAMENO = T3.FRAMENO
LEFT JOIN UM_CUSTOMER T4 ON T4.CUSTOMERCODE = T2.CUSTOMERCODE
LEFT JOIN CM_COMMONCODE T5 ON T4.PROFESSIONCODE = T5.COMMONCODE AND T5.CODETYPE = 'CC01'
LEFT JOIN (SELECT MAX(BUYDATE) AS BUYDATE ,FRAMENO FROM RT_INSURANCEBUY GROUP BY FRAMENO) T61 ON T1.FRAMENO =T61.FRAMENO
LEFT JOIN RT_INSURANCEBUY T6 ON T61.FRAMENO=T6.FRAMENO AND T61.BUYDATE=T6.BUYDATE
LEFT JOIN CM_STAFF T7 ON T3.ORIGINALSALEID = T7.STAFFPKID
LEFT JOIN CM_COMMONCODE T8 ON T6.INSURERCODE = T8.COMMONCODE AND T5.CODETYPE = 'CC12'
WHERE YEAR(T1.PURCHASEDATE) = YEAR(CURRENT TIMESTAMP) - 1 AND T6.INSURERCODE IS NOT NULL AND T3.ISALLOC = 'N' AND VALUE(T3.NOTCALL,'N') = 'N'
AND VALUE(T1.DELETED,'0') = '0' UNION ALL SELECT
'02' AS CUSTOMERALLOCTYPE,'续保客户' AS CUSTOMERALLOCTYPENAME,
CASE WHEN T1.CUSTOMERGRADE = 'A' THEN 'A'
WHEN T1.CUSTOMERGRADE = 'B' THEN 'B'
WHEN T1.CUSTOMERGRADE = 'C' THEN 'C'
WHEN T1.CUSTOMERGRADE = 'D' THEN 'D'
WHEN T1.CUSTOMERGRADE IS NULL THEN 'D' END AS CUSTOMERGRADE,
T4.CUSTOMERCODE,T4.CUSTOMERNAME,
T4.MOBILEPHONE,T4.MOBILEPHONE1,T4.TELEPHONE,
CASE WHEN T4.SEX = 'F' THEN '?' WHEN T4.SEX = 'M' THEN '?' END AS SEX,
T4.PROFESSIONCODE,T5.COMMONNAME AS PROFESSIONNAME,
T2.CARLICENSENO,T2.FRAMENO,T2.CARMODELPKID,
T8.COMMONNAME AS INSURERNAME, T6.INSURERCODE , T6.INSURANCEBUYDATE, T6.INSURANCEMATURITYDATE
,T3.ORIGINALSALEID,T7.FULLNAME AS ORIGINALSALENAME
,T3.ISALLOC
FROM RM_CARINFO T1
LEFT JOIN VM_CARINFO T2 ON T1.FRAMENO = T2.FRAMENO
LEFT JOIN RT_CARALLOCINFO T3 ON T1.FRAMENO = T3.FRAMENO
LEFT JOIN UM_CUSTOMER T4 ON T4.CUSTOMERCODE = T2.CUSTOMERCODE
LEFT JOIN CM_COMMONCODE T5 ON T4.PROFESSIONCODE = T5.COMMONCODE AND T5.CODETYPE = 'CC01'
LEFT JOIN (SELECT MAX(BUYDATE) AS BUYDATE ,FRAMENO FROM RT_INSURANCEBUY GROUP BY FRAMENO) T61 ON T1.FRAMENO =T61.FRAMENO
LEFT JOIN RT_INSURANCEBUY T6 ON T61.FRAMENO=T6.FRAMENO AND T61.BUYDATE=T6.BUYDATE
LEFT JOIN CM_STAFF T7 ON T3.ORIGINALSALEID = T7.STAFFPKID
LEFT JOIN CM_COMMONCODE T8 ON T6.INSURERCODE = T8.COMMONCODE AND T5.CODETYPE = 'CC12'
WHERE YEAR(T1.PURCHASEDATE) <> YEAR(CURRENT TIMESTAMP) - 1 AND T6.INSURERCODE IS NOT NULL AND T6.SALESTYPE = '1' AND T3.ISALLOC = 'N' AND VALUE(T3.NOTCALL,'N') = 'N'
AND VALUE(T1.DELETED,'0') = '0' UNION ALL
SELECT
'03' AS CUSTOMERALLOCTYPE, '应到期客户' AS CUSTOMERALLOCTYPENAME,
CASE WHEN T1.CUSTOMERGRADE = 'A' THEN 'A'
WHEN T1.CUSTOMERGRADE = 'B' THEN 'B'
WHEN T1.CUSTOMERGRADE = 'C' THEN 'C'
WHEN T1.CUSTOMERGRADE = 'D' THEN 'D'
WHEN T1.CUSTOMERGRADE IS NULL THEN 'D' END AS CUSTOMERGRADE,
T4.CUSTOMERCODE,T4.CUSTOMERNAME,
T4.MOBILEPHONE,T4.MOBILEPHONE1,T4.TELEPHONE,
CASE WHEN T4.SEX = 'F' THEN '?' WHEN T4.SEX = 'M' THEN '?' END AS SEX,
T4.PROFESSIONCODE,T5.COMMONNAME AS PROFESSIONNAME,
T2.CARLICENSENO,T2.FRAMENO,T2.CARMODELPKID,
T8.COMMONNAME AS INSURERNAME, T6.INSURERCODE , T6.INSURANCEBUYDATE, T6.INSURANCEMATURITYDATE
,T3.ORIGINALSALEID,T7.FULLNAME AS ORIGINALSALENAME
,T3.ISALLOC
FROM RM_CARINFO T1
LEFT JOIN VM_CARINFO T2 ON T1.FRAMENO = T2.FRAMENO
LEFT JOIN RT_CARALLOCINFO T3 ON T1.FRAMENO = T3.FRAMENO
LEFT JOIN UM_CUSTOMER T4 ON T4.CUSTOMERCODE = T2.CUSTOMERCODE
LEFT JOIN CM_COMMONCODE T5 ON T4.PROFESSIONCODE = T5.COMMONCODE AND T5.CODETYPE = 'CC01'
LEFT JOIN (SELECT MAX(BUYDATE) AS BUYDATE ,FRAMENO FROM RT_INSURANCEBUY GROUP BY FRAMENO) T61 ON T1.FRAMENO =T61.FRAMENO
LEFT JOIN RT_INSURANCEBUY T6 ON T61.FRAMENO=T6.FRAMENO AND T61.BUYDATE=T6.BUYDATE
LEFT JOIN CM_STAFF T7 ON T3.ORIGINALSALEID = T7.STAFFPKID
LEFT JOIN CM_COMMONCODE T8 ON T6.INSURERCODE = T8.COMMONCODE AND T5.CODETYPE = 'CC12'
WHERE T6.INSURERCODE IS NOT NULL AND T6.SALESTYPE = '0' AND T3.ISALLOC = 'N' AND VALUE(T3.NOTCALL,'N') = 'N'
AND VALUE(T1.DELETED,'0') = '0'
) T
WHERE 1=1 "); if(aQC.CustomerName != string.Empty)
{
sql.Append(" and T.CustomerName like '%" +aQC.CustomerName+ "%'");
}
if(aQC.CallNo != string.Empty)
{
sql.Append(" and (T.MobilePhone like '% " +aQC.CallNo+ "%' or T.MobilePhone1 like '%" +aQC.CallNo+ "%' or T.Telephone like '%" +aQC.CallNo+ "%')");
}
if(aQC.ProfessionCode != string.Empty)
{
sql.Append(" and T.ProfessionCode = "+ aQC.ProfessionCode);
}
if(aQC.CarLicenseNo != string.Empty)
{
sql.Append(" and T.CarLicenseNo like '%" +aQC.CarLicenseNo+ "%'");
}
if(aQC.FrameNo != string.Empty)
{
sql.Append(" and T.FrameNo like '%" +aQC.FrameNo+ "%' ");
}
if(aQC.CustomerAllocType != string.Empty)
{
sql.Append(" and T.CustomerAllocType = " + aQC.CustomerAllocType);
}
if(aQC.InsureCompanyCode != string.Empty)
{
sql.Append(" and T.InSurerCode = " + aQC.InsureCompanyCode);
}
if(aQC.CustomerGrade != string.Empty)
{
sql.Append(" and T.CustomerGrade = " + aQC.CustomerGrade);
}
if(aQC.InsuranceMaturityDateFrom != string.Empty)
{
sql.Append(" and T.InsuranceMaturityDate >= " + aQC.InsuranceMaturityDateFrom);
}
if(aQC.InsuranceMaturityDateEnd != string.Empty)
{
sql.Append(" and T.InsuranceMaturityDate <= " + aQC.InsuranceMaturityDateEnd);
} DataSet ds = new DataSet();
FillDataSet(sql.ToString(),ds,new string[]{"Tmp_CustomerAllocInfo"});
ds.AcceptChanges();
return ds;
}
DB2对年份的处理Year()的更多相关文章
- db2基础
DB2知识文档 一.db2 基础 基本语法 注释:"--"(两个减号) 字符串连接:"||" 如set msg='aaaa'||'bbbb',则msg为'aaa ...
- DB2 SQL 日期函数
DB2 SQL 日期函数1:CURRENT TIMESTAMP 函数:获取当前日期时间语法:CURRENT TIMESTAMP参数:当前日期时间返回值:当前日期时间 2:CURRENT DATE 函数 ...
- DB2常用命令
DB2安装启动服务中启动不了,可用command启动并查看windows系统的日志.1.启动数据库 db2start2.停止数据库 db2stop3.连接数据库运行 db2命令之前要先运行db2c ...
- DB2常用sql函数 (转载)
http://www.techonthenet.com/sql/index.php 一.字符转换函数 1.ASCII() 返回字符表达式最左端字符的ASCII 码值.在ASCII()函数中,纯数字的字 ...
- DB2 函数大全
DB2函数大全 函数名 函数解释 函数举例 AVG() 返回一组数值的平均值. SELECTAVG(SALARY)FROMBSEMPMS; CORR(),CORRELATION() 返回一对数值的关系 ...
- DB2日期和时间函数汇总
上一篇提到过在DB2中,可以通过SYSIBM.SYSDUMMY1.SYSIBM.DUAL获取寄存器中的值,也可以通过VALUES关键字获取寄存器中的值.则在这篇中,我们直接用VALUES关键字来看看这 ...
- DB2数据类型
DB2数据库的内置数据类型主要分成数值型(numeric).字符串型(character string).图形字符串(graphic string).二进制字符串型(binary string)或日期 ...
- DB2函数大全
DB2函数大全 函数名 函数解释 函数举例 AVG() 返回一组数值的平均值. SELECTAVG(SALARY)FROMBSEMPMS; CORR(),CORRELATION() 返回一对数值的关系 ...
- DB2数据库常用命令
--创建数据库 CREATE DATABASE example AUTOMATIC STORAGE YES --自动存储 ON 'D:\' DBPATH ON'D:\' --指定数据库控制文件的存储路 ...
随机推荐
- [原创] PostgreSQL Plus Advanced Server在Windows中配置双机热备流复制
一.系统环境 操作系统:Windows Server 2003/2008 两个节点分别为master与slave. 主节点master:172.27.19.28 备机点slave:172.27.19. ...
- iOSReachability判断网络连接状态
// // NetStateManage.h // // Created by miniu on 15/11/24. // Copyright © 2015年 mini. All rights ...
- java与IOS之间的RSA加解密
很简单的一个需求,ipad端给密码RSA加密,传到java后台,解密.RSA加密算法是基于一个密钥对的,分为公钥和私钥,一般情况公钥加密,私钥解密,但也可私钥加密,公钥解密.还可以验签,就是先用私钥对 ...
- xml数据读 swift
// // ViewController.swift // xml读写 // // Created by mac on 15/7/14. // Copyright (c) 2015年 fangyuha ...
- VC++ MFC 如何实现在编辑框中输出具有换行功能的文段 01
很久不来写东西了,昨天睡觉前写个小工具,突然,这玩意不会换行怎么整... 首先是第一步,获取字符串的长度,转载自白乔的文章. ------------------------------------- ...
- Notes of the scrum meeting(12.7)
meeting time:18:30~19:10p.m.,December 7th,2013 meeting place:3号公寓一层 attendees: 顾育豪 ...
- 搭建SpringMVC+MyBatis开发框架三
新增spingmvc.xml配置 在WEB-INF下新增spingmvc.xml,主要是配置spring扫描的包:  <?xml version="1.0" encodin ...
- C# 串口通信总结
在C#串口通信开发过程中有的产家只提供通信协议,这时候开发人员要自己根据协议来封装方法,有的产家比较人性化提供了封装好的通信协议方法供开发人员调用. 1.只提供通信协议(例如,今年早些时候开发的出钞机 ...
- PyDev for Eclipse 简介
PyDev 安装和配置 安装 PyDev 在安装 PyDev 之前,要保证您已经安装了 Java 1.4 或更高版本.Eclipse 以及 Python.接下来,开始安装 PyDev 插件. 启动 E ...
- [转载]关于android SDK安装Failed to fetch URL http://dl-ssl.google.com/android/repository/addons_list-1.xml出错
原文地址为:http://blog.csdn.net/springsky_/article/details/7442388 因为入行移动测试,所以很多测试环境的搭建.从中遇到了和这个GG同样的问题.怕 ...