1.开票时不知道是哪条商品价格低(未存盘的单据)
select * from tmp_dj_xsg212 where dj_sort = 73
select b.hscbj,a.* from tmp_dj_xsg212 a,spkfk b where a.spid=b.spid and a.gzid=‘LGZ02944744‘ and a.hshj<b.hscbj< p="">
2.处理采购入库单审核时报错单据
select * from tmp_dj_jha116 where xgdjbh=‘jhgfdb00043804‘
delete from tmp_dj_jha116 where xgdjbh=‘jhgfdb00043804‘
3.处理两集中订单不能提取,找出异常单据
select a.djbh,a.rq,b.danwbh,b.dwmch,b.zjm,a.beizhu,a.bm,a.ywy,b.shh,b.dzhdh,b.yhzhh,b.kehudengji,a.piaohao
from jxddhz a,mchk b where a.is_zx=‘否‘ and a.dwbh=b.dwbh and b.beactive=‘是‘ and left(a.djbh,6)= ‘JHFZFA‘
order by a.djbh
update jxddhz set dwbh=‘DWI00000351‘ where djbh=‘JHFZFA00012000‘
4.处理质管部建档商品异常,未写入spkfjc中
select spid from spkfk where spid not in(select spid from spkfjc)
insert into spkfjc (spid,kcshl,kcje)
select spid,0,0 from spkfk where spid not in(select spid from spkfjc)
5.处理销售结算查询中,结算员为空的明细
select a.djbh,a.shenhr,b.username from jxdjhz a,printwill_dj b where a.djbh=b.kaipiaodjbh and
a.rq=‘2008-09-23‘ and a.djbs=‘xsg‘ and a.shenhe=‘是‘ and a.shenhr =‘‘
update jxdjhz set shenhr=b.username from jxdjhz a,printwill_dj b where a.djbh=b.kaipiaodjbh and
a.rq=‘2008-09-23‘ and a.djbs=‘xsg‘ and a.shenhe=‘是‘ and a.shenhr =‘‘
6.处理非西药单据,不能提取或不能出库报错处理脚本
select a.djbh,a.rq,a.dwbh,a.shenhe,a.is_zx,a.bm,a.ywy,a.username,a.shenhr,
a.* from jxdjhz a where a.djbh=‘XSGFDB10277250‘
select hw,* from jxdjmx where djbh=‘XSGFDB10277250‘
update jxdjmx set isjs=‘是‘ where djbh=‘XSGFDB10277250‘
7. 商品异常,查询库存
declare @spbh varchar(20),
@spid char(11)
set @spbh=‘CAA004001G‘ --手工填写商品编号
set @spid= (select spid from spkfk where )
select spid,kcshl from spkfjc where
select hw,spid,hwshl from hwsp where
select * from xs_wck where
select * from jzt_wmscrsl where
select * from tmp_dj_xsg212 where
select a.is_zx,a.rq,a.djbh,a.username,a.ywy,b.spid,b.shl,b.hshj,b.hsje
from jxdjhz a,jxdjmx b where a.djbh=b.djbh and a.rq>=convert(char(10),DATEADD(mm, DATEDIFF(mm,0,getdate())-1, -0),20) --上月第一天
and a.is_zx=‘否‘ and a.djbs=‘xsg‘ and
8.销售部换单位调帐脚本
select danwbh,dwmch,dwsb,* from mchk where danwbh=‘P350602003X002FA‘
select danwbh,dwmch,dwsb,* from mchk where danwbh=‘P420102077X007FA‘
--更新 cwk, splsk, wlzhk 将 DWI00006850 更改为 DWI00008610
declare
@dwbh char(11),
@djbh char(14)
set @dwbh=‘DWI00008953‘
set @djbh=‘XSBFDB00022292‘
------------------------------------
select * from cwk where
------------------------------------
update cwk set where
update splsk set where
update wlzhk set where
9.删除采购员无用付款计划申请单
delete from fj_fkjh where djbh=‘YFFFDB00001484‘
10.处理商品在sphwph中无记录,导至无盘盘点问题
insert into sphwph (spid,hw,shl)
values
(‘SPH00029750‘,‘HWI00000270‘,‘-30‘)
11.清理结算错的结算单据
delete from printwill_dj where djbh in( ‘XSDFDB00529819‘,‘XSDFDB00529830‘ )
delete from ywjsmxk where djbh in( ‘XSDFDB00529819‘,‘XSDFDB00529830‘ )
delete from jsmxk where djbh in( ‘XSDFDB00529819‘,‘XSDFDB00529830‘ )
delete from cwk where kaipiaodjbh=‘XSGFDB10271836‘
12.处理财务结算日期选错单据,单据调整
update cwk set rq=‘2008-09-23‘ where rq=‘2008-10-23‘
update wlzhk set rq=‘2008-09-23‘ where rq=‘2008-10-23‘
update ywmxk set rq=‘2008-09-23‘ where rq=‘2008-10-23‘
update splsk set rq=‘2008-09-23‘ where rq=‘2008-10-23‘
13.处理西药商品已建档,但是销售开票中无法显示问题
update spkfk set is_zhongyao=‘否‘ where spbh=‘CAL061215G‘
14.财务金碟接口数据重传问题
update cwk set transmission=‘‘ where rq=‘2008-09-23‘ and djbh like ‘XS%‘
update ywjsmxk set transmission=‘‘ where rq=‘2008-09-23‘ and djbh like ‘XS%‘
15.处理税票组反应金额与含金额不一至问题(质管部退货问题,原因为有退补价)
select * from ywmxk where djbh=‘XSCFDB00089061‘
update cwk set hsje=je where djbh =‘XSCFDB00089061‘
update ywmxk set hshj=dj,hsje=je,she=0 where djbh =‘XSCFDB00089061‘
16.处理计生器械部单据部门选择,更新部门
update jxdjhz set bm=‘计生部‘ where djbh=‘XSGFDB10287823‘
17.运输部车辆管理系统增加新职员(前台无法增加)
insert into zhiydoc (dzyid,dzycode,dzyname,zjm,kl,lgnname,beactive,is_czy,is_ywy)
values
(‘ZIY10000147‘,‘TIANT‘,‘田天‘,‘TT‘,‘jl6bl7e5nikw3y76o3sqwo5wuxfg0t‘,‘TIANT‘,‘是‘,‘是‘,‘是‘)
18.系统表与职员对应关系
系统表相关:
select a.tbname,a.chnname,c.*
from tblist a,tbstru b,fldlist c
where a.tbname=b.tbname and b.fdname=c.fdname and a.tbname=‘mchk‘
select a.dzycode,a.dzyname,a.lgnname,c.bm,c.bmid,b.bmgwzhyid,a.dzyid
from zhiydoc a,hr_bmzhygw b,bmdoc c
where a.dzyid=b.dzyid and b.bmid=c.bmid order by a.dzyid
select c.*,a.dzyid,a.dzycode,a.dzyname,a.lgnname,a.beactive,a.is_czy,a.is_ywy,b.*
from zhiydoc a,skzymenu b,skmenu_model c,skmenu_zymbgx d
where a.dzyid=d.dzyid and b.lgnname=c.modelid and c.modelid=d.modelid order by a.dzyid,c.modelid
19.处理销售开票单提示实际结算价异常处理方法
select * from tmp_dj_xsg212 where gzid=‘LGZ02113651‘ and hesdj<>0 and (hesdj-hshj)*shl <> jec
select spid,spbh,spmch,shpgg,shpchd,shl,hshj,hscbj,hesdj,je,hsje,jec,(hshj-hesdj)*shl jjjec
from tmp_dj_xsg212 (nolock) where gzid=‘LGZ02410942‘ and hesdj<>0 and jec<>-(hshj-hesdj)*shl
20.月末数据结转
exec scc_ywyj ‘2008‘,‘7‘,‘‘,‘魏攀‘
21.查找异常数据字段位置
select * from queryfmx (nolock)
where (ondblfunc =‘wndict‘ or nexitfunc =‘wndict‘) and expcontent like ‘%shpchd%‘
22.处理财务报表金额异常单据
--1.检查当日单据是否有dwbh not like‘DWI%‘
select djbh,rq,dwbh,je into #cwbb1
from cwk where rq=‘2008-10-12‘ and djbs=‘jha‘
and dwbh not like‘DWI%‘
--2.查询对应单据在wlzhk的dwbh
select a.djbh,a.dwbh as newdwbh into #cwbb2 from wlzhk a,#cwbb1 b where a.djbh=b.djbh
--3.更新cwk异常的dwbh
update cwk set dwbh=b.newdwbh from cwk a,#cwbb2 b where a.djbh=b.djbh and a.dwbh in(select dwbh from #cwbb2)
--4.删除创建的临时表
drop table #cwbb1,#cwbb2
23.删除无用合同
delete from jxht_mx where djbh = ‘HETFDB00019109‘
delete from jxht_hz where djbh = ‘HETFDB00019109‘
24.处理hwsp与spkfjc成本不一至,金额不一至,手动同步
select a.spid,a.spbh,a.spmch,a.shpgg,a.shpchd,a.dw,b.kcshl,b.chbdj, b.kcje,
--cast(b.kcshl*b.chbdj as decimal(18,2)) as ‘预计更新后库存金额‘,b.kcje-cast(b.kcshl*b.chbdj as decimal(18,2)) as ‘差额‘,
--c.hwshl,c.chbdj,c.hwje,
--cast(c.hwshl*c.chbdj as decimal(18,2)) as ‘预计更新后货位金额‘,b.kcshl-c.hwshl as ‘数量差‘,
b.chbdj-c.chbdj as ‘成本差‘,b.kcje-c.hwje as ‘余额差‘
into #t_cy
from spkfk a(nolock),spkfjc b(nolock),hwsp c(nolock)
where a.beactive=‘是‘ and a.spid=b.spid and a.spid=c.spid and c.hw=‘HWI00000270‘ and b.kcshl<>0
and (b.kcje-c.hwje)<> 0
order by a.spbh
select * from #t_cy
update hwsp set chbdj=b.chbdj,hwje=b.kcje from hwsp a,spkfjc b
where a.spid=b.spid and a.hw=‘HWI00000270‘ and a.spid in(select spid from #t_cy)
drop table #t_cy
25.开票检查
select spid,spbh,spmch,shpgg,shpchd,shl,hshj,hscbj,hesdj,je,hsje,jec,(hshj-hesdj)*shl jjjec
from tmp_dj_xsg212 (nolock) where gzid=‘LGZ02410942‘ and hesdj<>0 and jec<>-(hshj-hesdj)*shl
select top 100 gzid,dj_sn,dj_sort,spid,spbh,spmch,shpgg,zbz,jlgg,dw,shpchd,hwshl,shl,hshj,hscbj,hesdj
from tmp_dj_xsg212 (nolock) where spbh=‘HAG002030C‘ gzid=‘LGZ02410942‘
select a.plh,a.caogsm,a.djbh,a.rq,e.danwbh,e.dwmch,a.zhy,a.bm,a.ywy,a.danjlx,
c.spbh,c.spmch,c.shpgg,c.shpchd,c.dw,b.shl,d.kcshl,b.hshj,c.hscbj,b.hesdj,b.jec
from caogaohz a(nolock),caogaomx b(nolock),spkfk c(nolock),spkfjc d(nolock),mchk e(nolock)
where a.plh=b.plh and b.spid=c.spid and c.spid=d.spid and a.dwbh=e.dwbh and a.rq=‘2008-06-18‘
and d.kcshl<b.shl
a.caogsm like‘‘
26.入库单据异常查询
--正常
select a.djbh,a.rq,d.dzyname as 收货员,b.danwbh,b.dwmch,
e.dzyname as ywy,b.dwbh ,g.bm,g.bmid,
a.djbh as djbh_lmisrk,a.rktype ,a.ydjbh,f.djbh as kaipiaodjbh
into #t_rk2 from jzt_gjrk_hz a (nolock)
left join (select * from zhiydoc (nolock)) d on a.ywy=d.dzyid
left join(select * from zhiydoc (nolock)) e on a.cgy=e.dzyid
left join jxdjhz f(nolock) on substring(a.ydjbh,1,3)+rtrim(‘FDB‘)+substring(a.ydjbh,4,8)=f.djbh
,mchk b (nolock),bmdoc g (nolock)
where a.dwbh=b.dwbh and a.bm=g.bmid and f.is_zx=‘否‘
and a.scf=‘1‘ and f.djbh not in (select distinct xgdjbh from tmp_dj_JHA116 (nolock))
order by a.djbh
--异常
select a.djbh,a.rq,d.dzyname as 收货员,b.danwbh,b.dwmch,
e.dzyname as ywy,b.dwbh ,g.bm,g.bmid,
a.djbh as djbh_lmisrk,a.rktype ,a.ydjbh,f.djbh as kaipiaodjbh
into #t_rk1 from jzt_gjrk_hz a (nolock)
left join (select * from zhiydoc (nolock)) d on a.ywy=d.dzyid
left join(select * from zhiydoc (nolock)) e on a.cgy=e.dzyid
left join jxdjhz f(nolock) on substring(a.ydjbh,1,3)+rtrim(‘FDB‘)+substring(a.ydjbh,4,8)=f.djbh
,mchk b (nolock),bmdoc g (nolock)
where a.dwbh=b.dwbh and a.bm=g.bmid
and a.scf=‘1‘ and f.djbh not in (select distinct xgdjbh from tmp_dj_JHA116 (nolock))
order by a.djbh
--查找异常单据
select a.*
from #t_rk1 a left join #t_rk2 b on a.djbh=b.djbh where b.djbh is null
--删除临时表
drop table #t_rk1, #t_rk2
27.CCERP V8.3 菜单详解
--------------------------------------------------------------------------------------------------
skmenu --系统默认菜单
zhiydoc --职员档案
skzymenu --系统角色菜单
skmenu_model --菜单模板
zhiyjsgx --职员角色关系
hr_bmzhygw --部门职员岗位
skmenu_zymbgx --职员模板关系
bmdoc --部门档案
******************************************
select * from skmenu --系统默认菜单 ccxlh,gnbh
select * from zhiydoc --职员档案 dzyid,dzyname
select * from skzymenu --系统角色菜单 lgnname(MOD00000010),ccxlh,gnbh
select * from skmenu_model --菜单模板 modelid(MOD00000010),modelname(结算组长)
select * from zhiyjsgx --职员角色关系 dzyid,djsid
select * from juesdoc --角色档案 djsid,djscode,djsname
select * from hr_bmzhygw --部门职员岗位 bmid,dzyid
select * from skmenu_zymbgx --职员模板关系 modelid,dzyid
select * from bmdoc --部门档案 bmid,bm
******************************************
--定义规则:
以ccxlh为标准进行命名(从左至右):
select * from skmenu where len(ltrim(ccxlh)) = 2 and mkbh = ‘A1‘
select * from skmenu where left(ccxlh,2) = ‘08‘
第一级根菜单
-------------------
00 进货管理
01 销售管理
02 办事处管理
03 财务管理
04 仓储管理
05 质量管理
06 库存管理
07 客户管理
08 综合管理
09 账簿单据
0A 经营报表报告
0B 综合查询
0C 决策分析
0D 基础维护
0E 其它功能
0F 窗口
-------------------
0805000500 则表示为:
08
0800
080001
080002
0801
080100
080101
...
0805
080500
08050000
0805000000
第左至右第9个菜单下的第五个(包含横线),从下到下,依此类推
00-01-02-03-04-05-06-07-08-09-0A-0B-0C... (从左到右)
00 |
0001 |
0002 | 从
0003 |
0004 | 上
0005 |
0006 | 到
0007 |
0008 | 下
0009 |
000A |
000B |
... ∨
--------------------------------------
相关功能查询演示:
select a.dzycode,a.dzyname,a.lgnname,c.bm,c.bmid,b.bmgwzhyid,a.dzyid
from zhiydoc a,hr_bmzhygw b,bmdoc c
where a.dzyid=b.dzyid and b.bmid=c.bmid order by a.dzyid
select c.*,a.dzyid,a.dzycode,a.dzyname,a.lgnname,a.beactive,a.is_czy,a.is_ywy,b.*
from zhiydoc a,skzymenu b,skmenu_model c,skmenu_zymbgx d
where a.dzyid=d.dzyid and b.lgnname=c.modelid and c.modelid=d.modelid order by a.dzyid,c.modelid
-------------------------------------------------------------------------------------------------
28.开票不能存盘,提示有重复商品,查找重复记录
declare @caogsm varchar (50)
set @caogsm = ‘%6570.65缪倩%‘
select b.spid, count(b.spid) as ‘重复次数‘ into #t_err from caogaohz a,caogaomx b where a.plh = b.plh and a.caogsm like @caogsm
group by b.spid having count(b.spid) >1
select b.*,a.spbh,a.spmch,a.shpgg,a.shpchd,a.dw
from spkfk a,#t_err b where a.spid=b.spid
drop table #t_err
29.西药流失找回(供参考,有待进一步完善)
alter proc [dbo].[Proc_wp_lszhcx]
@ls_ksrq char(10), --流失开始日期
@ls_zzrq char(10), --流失终止日期
@zh_ksrq char(10), --找回开始日期
@zh_zzrq char(10) --找回终止日期
as
--01
select distinct(dwbh),max(djbh) djbh into #lskhb
from cwk where rq< @ls_ksrq and djbh like‘XSA%‘
group by dwbh order by dwbh;
--02
select a.djbh,b.danwbh,a.ywy,a.rq,a.je into #lszhb
from cwk a,mchk b where a.dwbh=b.dwbh and a.dwbh in(select distinct(dwbh) dwbh from cwk where rq>= @zh_ksrq and rq<= @zh_zzrq and djbh like‘XSA%‘)
and a.dwbh not in(select distinct(dwbh) dwbh from cwk where rq>= @ls_ksrq and rq<= @ls_zzrq
and djbh like‘XSA%‘)
and a.djbh like‘XSA%‘ and a.rq>= @zh_ksrq and a.rq<= @zh_zzrq order by b.danwbh;
--03
select a.danwbh,b.rq,c.* into #lskhb1
from mchk a,cwk b,#lskhb c where a.dwbh=b.dwbh and b.djbh=c.djbh;
--04
select a.rq as lsrq,b.* into #lszh2
from #lskhb1 a,#lszhb b
where a.danwbh=b.danwbh
--05
select b.lsrq as ‘流失日期‘,b.djbh,b.rq as ‘找回日期‘,b.je,a.danwbh,a.dwmch,c.ywy
from mchk a,#lszh2 b,cwk c where a.danwbh=b.danwbh and b.djbh=c.djbh order by a.danwbh;
--06
drop table #lskhb,#lszhb, #lskhb1,#lszh2;
--exec Proc_wp_lszhcx ‘2008-09-01‘,‘2008-10-31‘,‘2008-11-01‘,‘2008-11-31‘
--29.非西药库存异常,spkfjc,hwsp有,sphwph无的处方法
select spid,kcshl from spkfjc where spid not in(select distinct spid from sphwph) and kcshl <>0
select top 1 * from sphwph
insert into sphwph
select spid,‘HWI00000270‘ as hw,‘‘ as pihao,‘‘ as baozhiqi,‘合格‘ as dangqzht,
kcshl as shl,0 as gebjj,‘‘ as miejph,‘‘ as sxrq,0 as tsshl,0 as zdshj,
0 as bkxshl,‘‘ as yanghriqi,0 as bukxshl
from spkfjc where spid not in(select distinct spid from sphwph) and kcshl <>0
--29.处理spkfjc与hwsp数量不一至,以spkfjc为准,更新脚本
update hwsp set hwshl = b.kcshl,chbdj = b.chbdj,hwje = b.kcje from hwsp a,spkfjc b
where a.spid = b.spid and a.hw = ‘HWI00000270‘ and b.spid in(‘SPH00019707‘,‘SPH00002447‘,‘SPH00000834‘)
--30向sphwph中插入spkfjc中有,sphwph中无的商品
insert into sphwph (spid,hw,shl)
values
(‘SPH00029564‘,‘HWI00000270‘,‘245.50‘)
select top 1 * from sphwph
select * from spkfjc where spid not in(select distinct spid from sphwph) and kcshl <>0
--select * from sphwph where spid = (select spid from spkfjc where spid not in(select distinct spid from sphwph) and kcshl <>0)
--31.SQL表字段属性查询
SELECT 表名=case when a.colorder=1 then d.name else‘‘ end,
字段序号=a.colorder,字段名=a.name,
类型=b.name,占用字节数=a.length,
小数位数=isnull(COLUMNPROPERTY(a.id,a.name,‘ Scale‘ ),0)
FROM syscolumns a left join
systypes b on a.xusertype=b.xusertype inner join
sysobjects d on a.id=d.id and d.xtype=‘U‘ and d.name<>‘dtproperties‘
where d.name=‘spkfk‘ --如果只查询指定表,加上此条件
order by a.id,a.colorder
--32.统计时空未处理单据数脚本
select a.* from
(
select count(*) as ‘单据数‘,‘采购订单‘ as ‘单据类型‘ from jzt_cgdd_hz
union
select count(*) as ‘单据数‘,‘非购入库‘ as ‘单据类型‘ from jzt_fgjrk_hz
union
select count(*) as ‘单据数‘,‘购进入库‘ as ‘单据类型‘ from jzt_gjrk_hz
union
select count(*) as ‘单据数‘,‘购进退出‘ as ‘单据类型‘ from jzt_gjtc_hz
union
select count(*) as ‘单据数‘,‘购退通知‘ as ‘单据类型‘ from jzt_gjtcxc_hz
union
select count(*) as ‘单据数‘,‘盘点单‘ as ‘单据类型‘ from jzt_pd_hz
union
select count(*) as ‘单据数‘,‘销售出库‘ as ‘单据类型‘ from jzt_xsck_hz
union
select count(*) as ‘单据数‘,‘销售下传‘ as ‘单据类型‘ from jzt_xxck_hz
union
select count(*) as ‘单据数‘,‘退回入库‘ as ‘单据类型‘ from jzt_xxth_hz
union
select count(*) as ‘单据数‘,‘退回开票‘ as ‘单据类型‘ from jzt_xxthxc_hz
) a
--33.检查网上订单超出经营范围明细查询
select c.rq,c.djbh,d.danwbh,d.dwmch,d.jingyjm,b.spbh,b.spmch,b.shpgg,b.yaowchf,b.shangplx,
case when substring(b.spbh,1,1) in (‘Z‘,‘X‘) then substring(b.spbh,1,1)
when substring(b.spbh,10,1) in (‘j‘,‘s‘,‘k‘) then substring(b.spbh,10,1)
when b.shangplx like ‘妊娠药品%‘ then ‘R‘
when b.spmch like ‘%胰岛素%‘ then ‘I‘
when b.yaowchf like ‘%麻黄碱%‘ then ‘M‘
when b.spbh_old = ‘V‘ then ‘V‘
when substring(b.spbh,10,1) in (‘C‘,‘D‘,‘E‘,‘G‘,‘H‘,‘I‘,‘N‘,‘O‘,‘P‘,‘Q‘,‘U‘,‘X‘,‘F‘) then ‘P‘
else ‘其它‘ END spsx
from jxddmx a,spkfk b,jxddhz c,mchk d
where a.spid = b.spid and a.djbh = c.djbh and c.dwbh = d.dwbh and a.djbh = ‘xsffdb00042509‘
order by b.yaowchf desc
--34.开票时不知道是哪条商品销售数量大于销售限制数量
方法一:未存盘的单据,正在开票中的
select * from tmp_dj_xsg212 where dj_sort = 73
select b.mindhshl,a.* from tmp_dj_xsg212 a,spkfk b where a.spid=b.spid and a.gzid=‘LGZ03438780‘ and b.mindhshl <>0 --and b.mindhshl<a.shl< p="">
方法二:已保存草稿的单据
select a.plh,a.caogsm,a.djbh,a.rq,e.danwbh,e.dwmch,a.ywy,a.danjlx,
c.spbh,c.spmch,c.shpgg,c.shpchd,c.dw,c.mindhshl,b.shl,d.kcshl,b.hshj
from caogaohz a(nolock),caogaomx b(nolock),spkfk c(nolock),spkfjc d(nolock),mchk e(nolock)
where a.plh=b.plh and b.spid=c.spid and c.spid=d.spid and a.dwbh=e.dwbh and a.rq=‘2009-02-05‘
and c.mindhshl <>0 and b.shl >c.mindhshl and a.caogsm like ‘%aaa%‘
--35.网上订单全程跟踪
SELECT distinct n.rq as ‘订单日期‘,a.rq as ‘开票日期‘,c.rq as ‘出库日期‘, d.danwbh, d.dwmch,
n.djbh as ‘网上订单编号‘ , n.ywy as ‘订单业务员‘, a.username as ‘订单操作员‘,
a.djbh AS ‘开票单据编号‘ , a.username AS ‘开票操作员‘, a.ywy as ‘开票业务员‘, a.hsje as ‘开票金额‘,
b.djbh AS ‘结算单据编号‘ , b.username AS ‘结算操作员‘,
c.djbh AS ‘出库单据编号‘ , c.username AS ‘出库操作员‘, c.hsje as ‘出库金额‘
FROM jxddhz n(nolock),jxdjmx m(nolock),jxdjhz a(nolock),printwill_dj b(nolock),cwk c(nolock),mchk d(nolock)
WHERE n.djbh = m.xgdjbh and a.djbh = m.djbh and a.djbh = b.kaipiaodjbh and a.djbh = c.kaipiaodjbh and c.dwbh = d.dwbh
and n.djbs = ‘xsf‘ and a.rq= ‘2009-02-05‘ and c.djbs = ‘xsa‘
ORDER BY a.djbh
--------------------------
declare @djbh char(14)
set @djbh = ‘xsffdb00041423‘
begin
if left(@djbh,6) = ‘XSFFDB‘
SELECT distinct n.rq as ‘订单日期‘,a.rq as ‘开票日期‘,c.rq as ‘出库日期‘, d.danwbh, d.dwmch,
n.djbh as ‘网上订单编号‘ , n.ywy as ‘订单业务员‘, a.username as ‘订单操作员‘,
a.djbh AS ‘开票单据编号‘ , a.username AS ‘开票操作员‘, a.ywy as ‘开票业务员‘, a.hsje as ‘开票金额‘,
b.djbh AS ‘结算单据编号‘ , b.username AS ‘结算操作员‘,
c.djbh AS ‘出库单据编号‘ , c.username AS ‘出库操作员‘, c.hsje as ‘出库金额‘
FROM jxddhz n(nolock),jxdjmx m(nolock),jxdjhz a(nolock),printwill_dj b(nolock),cwk c(nolock),mchk d(nolock)
WHERE n.djbh = m.xgdjbh and a.djbh = m.djbh and a.djbh = b.kaipiaodjbh and a.djbh = c.kaipiaodjbh and c.dwbh = d.dwbh
and n.djbs = ‘xsf‘ and c.djbs = ‘xsa‘ and n.djbh = @djbh
ORDER BY a.djbh
else if left(@djbh,6) = ‘XSGFDB‘
SELECT distinct n.rq as ‘订单日期‘,a.rq as ‘开票日期‘,c.rq as ‘出库日期‘, d.danwbh, d.dwmch,
n.djbh as ‘网上订单编号‘ , n.ywy as ‘订单业务员‘, a.username as ‘订单操作员‘,
a.djbh AS ‘开票单据编号‘ , a.username AS ‘开票操作员‘, a.ywy as ‘开票业务员‘, a.hsje as ‘开票金额‘,
b.djbh AS ‘结算单据编号‘ , b.username AS ‘结算操作员‘,
c.djbh AS ‘出库单据编号‘ , c.username AS ‘出库操作员‘, c.hsje as ‘出库金额‘
FROM jxddhz n(nolock),jxdjmx m(nolock),jxdjhz a(nolock),printwill_dj b(nolock),cwk c(nolock),mchk d(nolock)
WHERE n.djbh = m.xgdjbh and a.djbh = m.djbh and a.djbh = b.kaipiaodjbh and a.djbh = c.kaipiaodjbh and c.dwbh = d.dwbh
and n.djbs = ‘xsf‘ and c.djbs = ‘xsa‘ and a.djbh = @djbh
ORDER BY a.djbh
else if left(@djbh,6) = ‘XSDFDB‘
SELECT distinct n.rq as ‘订单日期‘,a.rq as ‘开票日期‘,c.rq as ‘出库日期‘, d.danwbh, d.dwmch,
n.djbh as ‘网上订单编号‘ , n.ywy as ‘订单业务员‘, a.username as ‘订单操作员‘,
a.djbh AS ‘开票单据编号‘ , a.username AS ‘开票操作员‘, a.ywy as ‘开票业务员‘, a.hsje as ‘开票金额‘,
b.djbh AS ‘结算单据编号‘ , b.username AS ‘结算操作员‘,
c.djbh AS ‘出库单据编号‘ , c.username AS ‘出库操作员‘, c.hsje as ‘出库金额‘
FROM jxddhz n(nolock),jxdjmx m(nolock),jxdjhz a(nolock),printwill_dj b(nolock),cwk c(nolock),mchk d(nolock)
WHERE n.djbh = m.xgdjbh and a.djbh = m.djbh and a.djbh = b.kaipiaodjbh and a.djbh = c.kaipiaodjbh and c.dwbh = d.dwbh
and n.djbs = ‘xsf‘ and c.djbs = ‘xsa‘ and b.djbh = @djbh
ORDER BY a.djbh
else if left(@djbh,6) = ‘XSAFDB‘
SELECT distinct n.rq as ‘订单日期‘,a.rq as ‘开票日期‘,c.rq as ‘出库日期‘, d.danwbh, d.dwmch,
n.djbh as ‘网上订单编号‘ , n.ywy as ‘订单业务员‘, a.username as ‘订单操作员‘,
a.djbh AS ‘开票单据编号‘ , a.username AS ‘开票操作员‘, a.ywy as ‘开票业务员‘, a.hsje as ‘开票金额‘,
b.djbh AS ‘结算单据编号‘ , b.username AS ‘结算操作员‘,
c.djbh AS ‘出库单据编号‘ , c.username AS ‘出库操作员‘, c.hsje as ‘出库金额‘
FROM jxddhz n(nolock),jxdjmx m(nolock),jxdjhz a(nolock),printwill_dj b(nolock),cwk c(nolock),mchk d(nolock)
WHERE n.djbh = m.xgdjbh and a.djbh = m.djbh and a.djbh = b.kaipiaodjbh and a.djbh = c.kaipiaodjbh and c.dwbh = d.dwbh
and n.djbs = ‘xsf‘ and c.djbs = ‘xsa‘ and c.djbh = @djbh
ORDER BY a.djbh
end
------------------------------
--36.按供应商查询库存
select distinct d.dwbh dwbh ,e.spid spid into #gj_spid
from mchk d
left join cwk c on d.dwbh=c.dwbh and c.rq>=:start_rq
and c.rq<=:end_rq and c.djbh like ‘JHA%‘
left join ywmxk e on e.djbh=c.djbh
where d.danwbh like :v_danwbh
select a.spbh,a.spmch,a.jlgg,a.shpchd,a.cgy,a.shpgg,b.kcshl,b.chbdj,b.kcshl*b.chbdj as ‘库存金额‘
from
spkfk a,spkfjc b , #gj_spid c where a.spid=b.spid
and c.spid=a.spid
drop table #gj_spid
--37.检查草稿单超范围商品明细
select c.rq,c.djbh,d.danwbh,d.dwmch,d.jingyjm,b.spbh,b.spmch,b.spmch,b.yaowchf,b.shangplx,
case when substring(b.spbh,1,1) in (‘Z‘,‘X‘) then substring(b.spbh,1,1)
when substring(b.spbh,10,1) in (‘j‘,‘s‘,‘k‘) then substring(b.spbh,10,1)
when b.shangplx like ‘妊娠药品%‘ then ‘R‘
when b.spmch like ‘%胰岛素%‘ then ‘I‘
when b.yaowchf like ‘%麻黄碱%‘ then ‘M‘
when b.spbh_old = ‘V‘ then ‘V‘
when substring(b.spbh,10,1) in (‘C‘,‘D‘,‘E‘,‘G‘,‘H‘,‘I‘,‘N‘,‘O‘,‘P‘,‘Q‘,‘U‘,‘X‘,‘F‘) then ‘P‘
else ‘**‘
end as spsx
from caogaomx a,spkfk b,caogaohz c,mchk d
where a.spid = b.spid and a.plh = c.plh and c.dwbh = d.dwbh and c.caogsm = ‘lllllllllll‘
order by b.yaowchf desc
--38.修改表字段长度示例
alter table FJ_FKJH alter column fkfs char(10)
--39.清理报告单系统数据库脚本(待完善)
select a.photo,b.spid,b.pihao,b.photoid,b.photoclass
from photoLib a,leeBatch b where a.photoid = b.photoid
and (left(b.pihao,2) = 07 or left(b.pihao,4) = 2007)
and b.pihao like ‘[0-9][0-9][0-9][0-9]%‘
--40.查询系统过程名
select name,id,crdate from sysobjects where xtype = ‘P‘ and name like ‘%excel%‘
--41.修改表字段长度时,有约束报错
ALTER TABLE gsp039 DROP CONSTRAINT DF__gsp039__dwmch__60BD35FF
alter table gsp039 alter column dwmch char(100)
ALTER TABLE gsp039 ADD CONSTRAINT DF__gsp039__dwmch__60BD35FF DEFAULT (‘‘) for dwmch
--42.处理未审核预付订单,已入库采购订单问题
(1).处理执行状态
select * from jxddhz a (nolock) where djbh = ‘JHFFDB00018156‘
select * from jxddmx a (nolock) where djbh = ‘JHFFDB00018156‘
update jxddhz set is_zx = ‘否‘ where djbh = ‘JHFFDB00018156‘
update jxddmx set is_zx = ‘否‘ where djbh = ‘JHFFDB00018156‘
(2).执行预付订单审核
---------------------------------------------------------------------------
(3).还原状态
select * from jxddhz a (nolock) where djbh = ‘JHFFDB00018156‘
select * from jxddmx a (nolock) where djbh = ‘JHFFDB00018156‘
update jxddhz set is_zx = ‘是‘ where djbh = ‘JHFFDB00018156‘
update jxddmx set is_zx = ‘是‘ where djbh = ‘JHFFDB00018156‘
--43.SQL语句大全
查看数据库启动时间
select convert(varchar(30),login_time,120) from master..sysprocesses where spid=1
查看链接服务器
sp_helplinkedsrvlogin
查看数据库里所有的存储过程和函数
use @database_name
sp_stored_procedures
创建加密的存储过程或函数在AS前面加WITH ENCRYPTION参数
解密加密过的存储过程和函数可以用sp_decrypt过程
--44.SQL字母大小写转换问题
select UPPER(dzycode) FROM zhiydoc WHERE zjm = ‘cf‘ --小写转大写
SELECT LOWER (dzycode) FROM zhiydoc WHERE zjm = ‘cf‘ --大写转小写
--45.结存异常分析
--01.货位商品检测
SELECT spid,hwshl,chbdj,hwje,CAST(hwshl*chbdj AS dec (14,2)) AS sjhwje
FROM hwsp WHERE hw = ‘HWI00000270‘ AND hwshl <>0 and ABS((hwshl*chbdj) -(hwje)) >100
--02.商品库房结存
SELECT spid,kcshl,chbdj,kcje,CAST(kcshl*chbdj AS dec (14,2)) AS sjkcje
FROM spkfjc WHERE kcshl <>0 and ABS((kcshl*chbdj) -(kcje)) >100
--03.商品流水库
SELECT a.spid,c.spbh,c.spmch,c.shpgg,c.shpchd,c.dw,a.jcshl,a.jcje,a.chbdj,
CAST(a.jcshl*a.chbdj AS dec (14,2)) AS sjjcje,CAST((a.jcshl*a.chbdj) -(a.jcje) AS dec (14,2)) AS jec
FROM splsk a(NOLOCK),
(SELECT spid,MAX(plh) plh FROM splsk (nolock) GROUP BY spid) AS t, spkfk c(nolock)
WHERE a.plh = t.plh AND a.spid = c.spid AND a.jcshl <>0 AND ABS((a.jcshl*a.chbdj) -(a.jcje)) >100