|
楼主 |
发表于 2014-11-5 20:40
|
显示全部楼层
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
jsxjd 发表于 2014-11-5 16:56
具体的 select 语句
谢谢,我刷新的是我们一个ERP系统中的某个表。
都是基本的SELECT语句。这个好像是SELECT语句无关。
如:
SELECT
TECH.dbo.COPTG.TG001 AS '单别',
TECH.dbo.COPTG.TG002 AS '单号',
TECH.dbo.COPTH.TH003 AS '序号',
CONVERT(varchar(100),cast(TECH.dbo.COPTG.TG003 as datetime),23) AS '销售日期',
--TECH.dbo.COPTG.TG003 AS '销货日期',
TECH.dbo.COPTG.TG004 AS '客户编号',
TECH.dbo.COPTG.TG005 AS '部门',
(SELECT TECH.dbo.CMSME.ME002 FROM TECH.dbo.CMSME WHERE TECH.dbo.CMSME.ME001=TECH.dbo.COPTG.TG005)AS '部门名称',
(SELECT TECH.dbo.CMSMV.MV002 FROM TECH.dbo.CMSMV WHERE TECH.dbo.CMSMV.MV001=TECH.dbo.COPTG.TG006)AS '业务员',
TECH.dbo.COPMA.MA003 AS '客户全称',
TECH.dbo.COPTH.TH004 AS '品号',
TECH.dbo.INVMB.MB002 AS '品名',
TECH.dbo.COPTH.TH009 AS '单位',
TECH.dbo.COPTH.TH008 AS '数量',
TECH.dbo.COPTH.TH012 AS '单价',
TECH.dbo.COPTH.TH013 AS '金额',
--(SELECT TECH.dbo.CMSMR.MR004 FROM TECH.dbo.CMSMR WHERE TECH.dbo.CMSMR.MR001='1' AND TECH.dbo.CMSMR.MR002=TECH.dbo.COPMA.MA017)AS '渠道',
(SELECT TECH.dbo.CMSMR.MR004 FROM TECH.dbo.CMSMR WHERE TECH.dbo.CMSMR.MR001='2' AND TECH.dbo.CMSMR.MR002=TECH.dbo.COPMA.MA076)AS '类型',
--(SELECT TECH.dbo.CMSMR.MR004 FROM TECH.dbo.CMSMR WHERE TECH.dbo.CMSMR.MR001='3' AND TECH.dbo.CMSMR.MR002=TECH.dbo.COPMA.MA018)AS '地区',
(SELECT TECH.dbo.CMSMR.MR004 FROM TECH.dbo.CMSMR WHERE TECH.dbo.CMSMR.MR001='4' AND TECH.dbo.CMSMR.MR002=TECH.dbo.COPMA.MA019)AS '国家',
(SELECT TECH.dbo.CMSMR.MR004 FROM TECH.dbo.CMSMR WHERE TECH.dbo.CMSMR.MR001='5' AND TECH.dbo.CMSMR.MR002=TECH.dbo.COPMA.MA077)AS '路线',
--判断大客户的省份,因只取大客户发货地址前两个字
CASE
WHEN TECH.dbo.COPMA.MA018='' THEN
CASE
WHEN LEFT(TECH.dbo.COPTG.TG008 ,2) ='安徽' THEN '安徽省'
WHEN LEFT(TECH.dbo.COPTG.TG008 ,2) ='上海' THEN '上海'
WHEN LEFT(TECH.dbo.COPTG.TG008 ,2) ='山东' THEN '山东'
WHEN LEFT(TECH.dbo.COPTG.TG008 ,2) ='江苏' THEN '江苏省'
WHEN LEFT(TECH.dbo.COPTG.TG008 ,2) ='浙江' THEN '浙江省'
WHEN LEFT(TECH.dbo.COPTG.TG008 ,2) ='福建' THEN '福建省'
WHEN LEFT(TECH.dbo.COPTG.TG008 ,2) ='宁夏' THEN '宁夏'
WHEN LEFT(TECH.dbo.COPTG.TG008 ,2) ='甘肃' THEN '甘肃省'
WHEN LEFT(TECH.dbo.COPTG.TG008 ,2) ='新疆' THEN '新疆'
WHEN LEFT(TECH.dbo.COPTG.TG008 ,2) ='陕西' THEN '陕西省'
WHEN LEFT(TECH.dbo.COPTG.TG008 ,2) ='青海' THEN '青海'
WHEN LEFT(TECH.dbo.COPTG.TG008 ,2) ='北京' THEN '北京'
WHEN LEFT(TECH.dbo.COPTG.TG008 ,2) ='河北' THEN '河北省'
WHEN LEFT(TECH.dbo.COPTG.TG008 ,2) ='河南' THEN '河南省'
WHEN LEFT(TECH.dbo.COPTG.TG008 ,2) ='黑龙' THEN '黑龙江省'
WHEN LEFT(TECH.dbo.COPTG.TG008 ,2) ='吉林' THEN '吉林省'
WHEN LEFT(TECH.dbo.COPTG.TG008 ,2) ='辽宁' THEN '辽宁省'
WHEN LEFT(TECH.dbo.COPTG.TG008 ,2) ='山西' THEN '山西省'
WHEN LEFT(TECH.dbo.COPTG.TG008 ,2) ='天津' THEN '天津'
WHEN LEFT(TECH.dbo.COPTG.TG008 ,2) ='湖北' THEN '湖北省'
WHEN LEFT(TECH.dbo.COPTG.TG008 ,2) ='湖南' THEN '湖南省'
WHEN LEFT(TECH.dbo.COPTG.TG008 ,2) ='四川' THEN '四川省'
WHEN LEFT(TECH.dbo.COPTG.TG008 ,2) ='重庆' THEN '重庆'
WHEN LEFT(TECH.dbo.COPTG.TG008 ,2) ='云南' THEN '云南省'
WHEN LEFT(TECH.dbo.COPTG.TG008 ,2) ='贵州' THEN '贵州省'
WHEN LEFT(TECH.dbo.COPTG.TG008 ,2) ='江西' THEN '江西省'
WHEN LEFT(TECH.dbo.COPTG.TG008 ,2) ='广东' THEN '广东省'
WHEN LEFT(TECH.dbo.COPTG.TG008 ,2) ='广西' THEN '广西'
WHEN LEFT(TECH.dbo.COPTG.TG008 ,2) ='海南' THEN '海南省'
WHEN LEFT(TECH.dbo.COPTG.TG008 ,2) ='东内' THEN '东蒙'
WHEN LEFT(TECH.dbo.COPTG.TG008 ,2) ='西内' THEN '西蒙'
WHEN LEFT(TECH.dbo.COPTG.TG008 ,2) ='西藏' THEN '西藏'
END
WHEN TECH.dbo.COPMA.MA018 <> '' THEN (SELECT TECH.dbo.CMSMR.MR004 FROM TECH.dbo.CMSMR WHERE TECH.dbo.CMSMR.MR001='3' AND TECH.dbo.CMSMR.MR002=TECH.dbo.COPMA.MA018)
END AS 销售省份,
TECH.dbo.COPTH.TH037 AS '本币税前金额',
TECH.dbo.COPTH.TH038 AS '本币税额'
--LEFT(TECH.dbo.COPTG.TG008 ,2) AS '送货省份'
FROM TECH.dbo.COPTG
JOIN TECH.dbo.COPTH
ON TECH.dbo.COPTG.TG001=TECH.dbo.COPTH.TH001 AND TECH.dbo.COPTG.TG002=TECH.dbo.COPTH.TH002
JOIN TECH.dbo.COPMA
ON TECH.dbo.COPTG.TG004=TECH.dbo.COPMA.MA001
JOIN TECH.dbo.INVMB
ON TECH.dbo.COPTH.TH004=TECH.dbo.INVMB.MB001
WHERE TECH.dbo.COPTG.TG003 BETWEEN '20130101' and '20141231'
AND TECH.dbo.COPTH.TH020='Y'
AND TECH.dbo.COPTH.TH001='SH03'
|
|