Mongoosej.Blog.Software.Programming.SQL.Procedure


    K.Database.SqlServer.procedure.contrast_a.sql

    1. if exists(select name from sysobjects where name='contrast_a_1' and type='P')
    2. drop procedure contrast_a_1;
    3. if exists(select name from sysobjects where name='contrast_a_2' and type='P')
    4. drop procedure contrast_a_2;
    5. create procedure contrast_a_1
    6. (
    7. @a varchar(10),
    8. @b varchar(10) output
    9. )
    10. as
    11. begin
    12. if @a>10
    13. begin
    14. set @b=@a+'>10'
    15. end
    16. else if @a=10
    17. begin
    18. set @b=@a+'=10'
    19. end
    20. else if @a<10
    21. begin
    22. set @b=@a+'<10'
    23. end
    24. else
    25. begin
    26. set @b='unkonwn'
    27. end
    28. end
    29. create procedure contrast_a_2
    30. (
    31. @a varchar(10),
    32. @b varchar(10) output
    33. )
    34. as
    35. begin
    36. if @a>10
    37. begin
    38. set @b=@a+'>10'
    39. end
    40. if @a=10
    41. begin
    42. set @b=@a+'=10'
    43. end
    44. if @a<10
    45. begin
    46. set @b=@a+'<10'
    47. end
    48. else
    49. begin
    50. set @b='unkonwn'
    51. end
    52. end
    53. declare
    54. @c varchar(10)
    55. exec contrast_a_1
    56. @a=10,
    57. @b=@c output
    58. print @c
    59. declare
    60. @d varchar(10)
    61. exec contrast_a_2
    62. @a=10,
    63. @b=@d output
    64. print @d

    K.Database.SqlServer.procedure.example_a.sql

    1. -----------------------------------------------------------------------------------------------------------------------------------------------------------------------------Intplog
    2. ------------------------------------------------------------------------------------------------create table
    3. if exists(select name from sysobjects where name='Intplog_job' and type='U')
    4. drop table Intplog_job;
    5. if exists(select name from sysobjects where name='Intplog_equip' and type='U')
    6. drop table Intplog_equip;
    7. create table Intplog_job
    8. (
    9. wkid varchar(50),
    10. wmsid varchar(50),
    11. wcsid varchar(50),
    12. pltcode varchar(50),
    13. frmpositionno varchar(50),
    14. frmstationno varchar(50),
    15. topositionno varchar(50),
    16. tostationno varchar(50),
    17. iworktype varchar(50),
    18. istatus varchar(50),
    19. sdesc varchar(50),
    20. ifirst varchar(50),
    21. dinsert datetime,
    22. dexecute datetime,
    23. dover datetime,
    24. xd varchar(50),
    25. sf_dy varchar(50)
    26. )
    27. create table Intplog_equip
    28. (
    29. wcsid varchar(50),
    30. tunno varchar(50),
    31. errtype varchar(50),
    32. errcode varchar(50),
    33. status varchar(50),
    34. )
    35. ------------------------------------------------------------------------------------------------create view
    36. if exists(select name from sysobjects where name='V_TASK_STOCK_CHECK_DTL' and type='V')
    37. drop view V_TASK_STOCK_CHECK_DTL;
    38. create view V_TASK_STOCK_CHECK_DTL
    39. (
    40. wkid,
    41. wmsid,
    42. wcsid,
    43. pltcode,
    44. frmpositionno,
    45. frmstationno,
    46. topositionno,
    47. tostationno,
    48. iworktype,
    49. istatus,
    50. sdesc,
    51. ifirst,
    52. dinsert,
    53. dexecute,
    54. dover,
    55. xd,
    56. sf_dy
    57. )
    58. as
    59. select wkid,wmsid,wcsid,pltcode,frmpositionno,frmstationno,topositionno,tostationno,iworktype,istatus,sdesc,ifirst,dinsert,dexecute,dover,xd,sf_dy from Intplog_job;
    60. ------------------------------------------------------------------------------------------------Procedure P_STOCK_ONLINE_STAT
    61. if exists(select name from sysobjects where name='P_STOCK_ONLINE_STAT' and type='P')
    62. drop procedure P_STOCK_ONLINE_STAT;
    63. create procedure P_STOCK_ONLINE_STAT
    64. (
    65. @iv_sn varchar(50),
    66. @iv_ms_serial_nbr varchar(50),
    67. @iv_ws_serial_nbr varchar(50),
    68. @iv_case_nbr varchar(50),
    69. @iv_oprt_rslt varchar(50),
    70. @ov_succ_rslt varchar(50) output,
    71. @ov_succ_code varchar(50) output
    72. )
    73. as
    74. update Intplog_job set wmsid=@iv_ms_serial_nbr,wcsid=@iv_ws_serial_nbr,istatus=@iv_oprt_rslt where wkid=@iv_ms_serial_nbr;
    75. if(@@rowcount=1)
    76. set @ov_succ_rslt='1';
    77. else
    78. set @ov_succ_rslt='0';
    79. ------------------------------------------------------------------------------------------------Procedure P_STOCK_TASK
    80. if exists(select name from sysobjects where name='P_STOCK_TASK' and type='P')
    81. drop procedure P_STOCK_TASK;
    82. create procedure P_STOCK_TASK
    83. (
    84. @iv_sn varchar(50),
    85. @iv_ms_serial_nbr varchar(50),
    86. @iv_ws_serial_nbr varchar(50),
    87. @iv_case_nbr varchar(50),
    88. @iv_oprt_error varchar(50),
    89. @ov_succ_rslt varchar(50) output,
    90. @ov_succ_code varchar(50) output
    91. )
    92. as
    93. update Intplog_job set wmsid=@iv_ms_serial_nbr,wcsid=@iv_ws_serial_nbr,istatus=@iv_oprt_error where wkid=@iv_ms_serial_nbr;
    94. if(@@rowcount=1)
    95. set @ov_succ_rslt='1';
    96. else
    97. set @ov_succ_rslt='0';
    98. ------------------------------------------------------------------------------------------------Procedure P_EQPMT_STAT_ITF
    99. if exists(select name from sysobjects where name='P_EQPMT_STAT_ITF' and type='P')
    100. drop procedure P_EQPMT_STAT_ITF;
    101. create procedure P_EQPMT_STAT_ITF
    102. (
    103. @iv_ws_serial_nbr varchar(50),
    104. @iv_lane_way varchar(50),
    105. @iv_eqpmt_id varchar(50),
    106. @iv_error_code varchar(50),
    107. @ov_succ_rslt varchar(50) output,
    108. @ov_succ_code varchar(50) output
    109. )
    110. as
    111. set nocount on;
    112. insert into Intplog_equip(wcsid,errtype,errcode) values( @iv_ws_serial_nbr,@iv_eqpmt_id,@iv_error_code);
    113. if(@@rowcount=1)
    114. set @ov_succ_rslt='1';
    115. else
    116. set @ov_succ_rslt='0';
    117. declare
    118. @ov_succ_rslt varchar(50),
    119. @ov_succ_code varchar(50)
    120. exec P_EQPMT_STAT_ITF
    121. @iv_ws_serial_nbr='123afraf',
    122. @iv_lane_way='12',
    123. @iv_eqpmt_id='531',
    124. @iv_error_code='9001',
    125. @ov_succ_rslt=@ov_succ_rslt output,
    126. @ov_succ_code=@ov_succ_code output
    127. print @ov_succ_rslt
    128. print @ov_succ_code
    129. -----------------------------------------------------------------------------------------------------------------------------------------------------------------------------Jointown
    130. ------------------------------------------------------------------------------------------------create table
    131. if exists(select name from sysobjects where name='Jointown_job' and type='U')
    132. drop table Jointown_job;
    133. create table Jointown_job
    134. (
    135. ZT varchar(50),
    136. LIUS_NO varchar(50),
    137. TUOP_BARCODE varchar(50),
    138. LTKZY_WAY varchar(50),
    139. ZHIL_STATE varchar(50),
    140. FROM_LOC varchar(50),
    141. TO_LOC varchar(50),
    142. ERR_MSG varchar(50),
    143. LTK_ORDER varchar(50),
    144. CREATE_TIME datetime,
    145. ZHIX_TIME datetime,
    146. HUIP_SIGN varchar(50),
    147. ZHANT_NO varchar(50)
    148. )
    149. ------------------------------------------------------------------------------------------------create view
    150. if exists(select name from sysobjects where name='VIW_LTK_CKZL' and type='V')
    151. drop view VIW_LTK_CKZL;
    152. create view VIW_LTK_CKZL
    153. (
    154. ZT,
    155. LIUS_NO,
    156. TUOP_BARCODE,
    157. LTKZY_WAY,
    158. ZHIL_STATE,
    159. FROM_LOC,
    160. TO_LOC,
    161. ERR_MSG,
    162. LTK_ORDER,
    163. CREATE_TIME,
    164. ZHIX_TIME,
    165. HUIP_SIGN,
    166. ZHANT_NO
    167. )
    168. as
    169. select ZT,LIUS_NO,TUOP_BARCODE,LTKZY_WAY,ZHIL_STATE,FROM_LOC,TO_LOC,ERR_MSG,LTK_ORDER,CREATE_TIME,ZHIX_TIME,HUIP_SIGN,ZHANT_NO from Jointown_job
    170. ------------------------------------------------------------------------------------------------Procedure P_LTK_TASK
    171. if exists(select name from sysobjects where name='P_LTK_TASK' and type='P')
    172. drop procedure P_LTK_TASK;
    173. create procedure P_LTK_TASK
    174. (
    175. @is_sn varchar(50),
    176. @icode varchar(50),
    177. @ivalue varchar(50),
    178. @o_retvar varchar(50) output
    179. )
    180. as
    181. begin
    182. if @is_sn='XDZT'--新的状态
    183. begin
    184. --if @icode in('501','502','503','504','505','506','507','508','509','510','511','512','513','514','515') AND @ivalue in('1','-1')
    185. if @icode in('709','710','711','712','724','725','726','727') AND @ivalue in('1','-1')
    186. set @o_retvar='1';
    187. else
    188. set @o_retvar='0';
    189. end
    190. else if @is_sn='BCR_R'--扫码入库
    191. begin
    192. declare @jobid4 varchar(50);
    193. set @jobid4=Ltrim(Str(Round(1000000*Rand()+1000000,0)));
    194. if Cast(@ivalue as int)<10000000000
    195. set @o_retvar='1@'+@jobid4+'@0011001001@40@采购入库 商品 批号 数量';
    196. else
    197. set @o_retvar='0@异常信息';
    198. end
    199. else if @is_sn='BCR_D'--空托盘组入库
    200. begin
    201. declare @jobid5 varchar(50);
    202. set @jobid5=Ltrim(Str(Round(1000000*Rand()+1000000,0)));
    203. if Cast(@ivalue as int)<10000000000
    204. set @o_retvar='1@'+@jobid5+'@0011001001@40@空托盘入库 商品 批号 数量';
    205. else
    206. set @o_retvar='0@异常信息';
    207. end
    208. else if @is_sn='BCR_MPR'--码盘入库
    209. begin
    210. declare @jobid2 varchar(50);
    211. set @jobid2=Ltrim(Str(Round(1000000*Rand()+1000000,0)));
    212. if @icode in('402','407','410','414','419','422')
    213. set @o_retvar='1@'+@jobid2+'@0011001001@40@码盘入库 商品 批号 数量';
    214. else
    215. set @o_retvar='0@异常信息';
    216. end
    217. else if @is_sn='BCR_RGMPR'--人工码盘入库
    218. begin
    219. declare @jobid3 varchar(50);
    220. set @jobid3=Ltrim(Str(Round(1000000*Rand()+1000000,0)));
    221. if @icode in('386')
    222. set @o_retvar='1@'+@jobid3+'@0011001001@40@人工码盘入库 商品 批号 数量';
    223. else
    224. set @o_retvar='0@异常信息';
    225. end
    226. else if @is_sn='RKEND'--入库完成
    227. begin
    228. if Cast(@ivalue as int)<10000000000
    229. set @o_retvar='1@OK';
    230. else
    231. set @o_retvar='0@异常信息';
    232. end
    233. else if @is_sn='ZLCX'--出库指令查询
    234. begin
    235. --if @icode in('01','02','03','04','05','06','07','08','09','10','11','12')
    236. if @icode is null or @icode=''
    237. begin
    238. declare @jobid1 varchar(50);
    239. set @jobid1=Ltrim(Str(Round(1000000*Rand()+1000000,0)));
    240. insert into VIW_LTK_CKZL(ZT,LIUS_NO,TUOP_BARCODE,LTKZY_WAY,ZHIL_STATE,FROM_LOC,TO_LOC,ERR_MSG,LTK_ORDER,CREATE_TIME,ZHIX_TIME,HUIP_SIGN,ZHANT_NO)
    241. values('1',@jobid1,'800001','2','0','0011001001000','','','40',Current_Timestamp,Current_Timestamp,'N','126');
    242. set @o_retvar='select * from VIW_LTK_CKZL where LIUS_NO='+@jobid1;
    243. print @o_retvar;
    244. end
    245. else
    246. set @o_retvar='0@异常信息ZLCX';
    247. end
    248. else if @is_sn='BCR_C'--出库完成
    249. begin
    250. --if @icode in('217','218','213','209','347','500')
    251. if @icode in('126','130','136','141')
    252. set @o_retvar='1@'+@icode+'@出库任务 商品 批号 数量';
    253. else
    254. set @o_retvar='0@异常信息';
    255. end
    256. else if @is_sn='BCR_MPC'--托盘到达码垛位
    257. begin
    258. if @icode in('402','407','410','141','419','422')
    259. set @o_retvar='1@OK';
    260. else
    261. set @o_retvar='0@异常信息';
    262. end
    263. else if @is_sn='MODE_ONLINE'--拣选回库
    264. begin
    265. declare @jobid6 varchar(50);
    266. set @jobid6=Ltrim(Str(Round(1000000*Rand()+1000000,0)));
    267. if Cast(@icode as int)<10000000000
    268. set @o_retvar='1@'+@jobid6+'@2@0011001001@40';
    269. else if @icode='4' and Cast(@icode as int)=0
    270. set @o_retvar='1@4@4@12@499@40';
    271. else if @icode='2' and Cast(@icode as int)=0
    272. set @o_retvar='0@托盘已空,请取出托盘,无需回盘';
    273. end
    274. else if @is_sn='KTPCK'--空托盘出库
    275. begin
    276. set @o_retvar='1@123';
    277. end
    278. else
    279. begin
    280. set @o_retvar='0@传入参数'+@is_sn+',异常,未约定该参数';
    281. end
    282. end
    283. ------------------------------------------------------------------------------------------------Procedure P_LTK_TASK test
    284. declare
    285. @a varchar(50)
    286. exec P_LTK_TASK
    287. @is_sn='XDZT',
    288. @icode='724',
    289. @ivalue=-1,
    290. @o_retvar=@a output
    291. print @a