-- if SP is existed, drop it.
if (object_id('InvHoldToDPS', 'P') is not null)
drop proc InvHoldToDPS
GO -- craete new SP.
CREATE PROCEDURE dbo.InvHoldToDPS
AS
BEGIN
SET NOCOUNT ON -- delete target table.
--delete from inv1_holdsForPrice -- delte temp table.
--delete from inv1_holdsForPriceTemp declare @headLine char(2000)
-- get the first record which is title info.
set @headLine = (select top 1 feedValue from inv1_holdsForPriceTemp) IF LEFT(@headLine, 6) <> 'IMAHDR'
BEGIN
print 'Error'
-- wirte the info to the log table.
-- exit (return)
END declare @priceDate char(8)
select @priceDate = SUBSTRING(@headLine, 26,8) -- store Price Date "YYYYMMDD" declare @j int
select @j = 0 declare curFV_cur cursor for
select feedValue from inv1_holdsForPriceTemp for read only declare @feedValue char(2000)
select @feedValue = '' open curFV_cur
fetch next from curFV_cur into @feedValue while (@@fetch_status = 0)
begin
if(LEFT(@feedValue, 6) <> 'IMAHDR' And Left(@feedValue, 6) <> 'IMATRL') -- Head and Feet record
begin
if(LEN(ltrim(rtrim(SUBSTRING(@feedValue, 39, 9))))) = 9
begin
declare @inv1_acct_num decimal
declare @inv1_grp_acct_num varchar
declare @fmr_fund_num varchar
declare @fmr_subport_num char
declare @fmr_cusip varchar
declare @acct varchar
declare @scty_cusip varchar
declare @scty_date varchar
declare @scty_qual varchar
declare @hold_date varchar
declare @shares decimal
declare @cost decimal
declare @amort decimal
declare @accr_incom decimal
declare @market decimal
declare @price decimal
declare @fx_rate decimal
declare @price_date varchar select @inv1_acct_num = LTRIM(RTRIM(SUBSTRING(@feedValue, 1, 15)))
select @inv1_grp_acct_num = LTRIM(RTRIM(SUBSTRING(@feedValue, 16, 15)))
select @fmr_fund_num = LTRIM(RTRIM(SUBSTRING(@feedValue, 31, 6)))
select @fmr_subport_num = LTRIM(RTRIM(SUBSTRING(@feedValue, 37, 2)))
select @fmr_cusip = LTRIM(RTRIM(SUBSTRING(@feedValue, 39, 9)))
select @acct = LTRIM(RTRIM(SUBSTRING(@feedValue, 59, 15)))
select @scty_cusip = LTRIM(RTRIM(SUBSTRING(@feedValue, 74, 9)))
select @scty_date = LTRIM(RTRIM(SUBSTRING(@feedValue, 83, 8)))
select @scty_qual = LTRIM(RTRIM(SUBSTRING(@feedValue, 91, 5)))
select @hold_date = LTRIM(RTRIM(SUBSTRING(@feedValue, 96, 8)))
select @shares = SUBSTRING(@feedValue, 104, 15) + '.' + SUBSTRING(@feedValue, 109, 4)
select @cost = SUBSTRING(@feedValue, 123, 16) + '.' + SUBSTRING(@feedValue, 139, 2)
select @amort = SUBSTRING(@feedValue, 141, 16) + '.' + SUBSTRING(@feedValue, 157, 2)
select @accr_incom = SUBSTRING(@feedValue, 159, 16) + '.' + SUBSTRING(@feedValue, 175, 2)
select @market = SUBSTRING(@feedValue, 177, 16) + '.' + SUBSTRING(@feedValue, 193, 2)
select @price = SUBSTRING(@feedValue, 195, 77) + '.' + SUBSTRING(@feedValue, 206, 8)
select @fx_rate = SUBSTRING(@feedValue, 214, 7) + '.' + SUBSTRING(@feedValue, 211, 9)
select @price_date = @priceDate if(SUBSTRING(@feedValue, 48, 1)) = ''
begin
exec dbo.spUpd_inv1_holdsForPrice
@inv1_acct_num,
@inv1_grp_acct_num,
@fmr_fund_num,
@fmr_subport_num,
@fmr_cusip,
@acct,
@scty_cusip,
@scty_date,
@scty_qual,
@hold_date,
@shares,
@cost,
@amort,
@accr_incom,
@market,
@price,
@fx_rate,
@price_date end
else if(SUBSTRING(@feedValue, 48, 1)) = ''
begin
declare @inv1_acct_num2 decimal
declare @inv1_grp_acct_num2 varchar
declare @fmr_fund_num2 varchar
declare @fmr_subport_num2 char
declare @fmr_cusip2 varchar
declare @sec_desc varchar
declare @sec_country_code varchar
declare @traded_ccy varchar
declare @income_ccy varchar
declare @unit_of_calc decimal select @inv1_acct_num2 = LTRIM(RTRIM(SUBSTRING(@feedValue, 1, 15)))
select @inv1_grp_acct_num2 = LTRIM(RTRIM(SUBSTRING(@feedValue, 16, 15)))
select @fmr_fund_num2 = LTRIM(RTRIM(SUBSTRING(@feedValue, 31, 6)))
select @fmr_subport_num2 = LTRIM(RTRIM(SUBSTRING(@feedValue, 37, 2)))
select @fmr_cusip2 = LTRIM(RTRIM(SUBSTRING(@feedValue, 39, 9))) select @sec_desc = LTRIM(RTRIM(SUBSTRING(@feedValue, 59, 30)))
select @sec_country_code = LTRIM(RTRIM(SUBSTRING(@feedValue, 89, 4)))
select @traded_ccy = LTRIM(RTRIM(SUBSTRING(@feedValue, 93, 4)))
select @income_ccy = LTRIM(RTRIM(SUBSTRING(@feedValue, 97, 4)))
select @unit_of_calc = LTRIM(RTRIM(SUBSTRING(@feedValue, 158, 10))) + '.' + LTRIM(RTRIM(SUBSTRING(@feedValue, 168, 4))) exec spUpd_inv1_holdsForPrice2
@inv1_acct_num2,
@inv1_grp_acct_num2,
@fmr_fund_num2,
@fmr_subport_num2,
@fmr_cusip2,
@sec_desc,
@sec_country_code,
@traded_ccy,
@income_ccy,
@unit_of_calc
end
end
end select @j = @j + 1
fetch next from curFV_cur into @feedValue
end
close curFV_cur
deallocate curFV_cur END
SET NOCOUNT OFF --exec spUpdateBDAatInv1 --exec spUpdateEquitiesMasterInv1 GO

Microsoft SQL Server 存储过程举例的更多相关文章

  1. Microsoft SQL Server 存储过程

    Microsoft SQL Server 存储过程 TRIGGER DDL触发器:主要用于防止对数据库架构.视图.表.存储过程等进行的某些修改:DDL事件是指对数据库CREATE,ALTER,DROP ...

  2. sql: MySQL and Microsoft SQL Server Stored Procedures IN, OUT using csharp code

    MySQL存储过程: #插入一条返回值涂聚文注 DELIMITER $$ DROP PROCEDURE IF EXISTS `geovindu`.`proc_Insert_BookKindOut` $ ...

  3. SQL Server存储过程

    创建于2016-12-24 16:12:19 存储过程 概念: 1.存储过程是在数据库管理系统中保存的.预先编译的.能实现某种功能的SQL程序,它是数据库应用中运用比较广泛的 一种数据对象. 2.存储 ...

  4. 从 Microsoft SQL Server 迁移到 Oracle

    来源于:http://www.oracle.com/technetwork/cn/database/migration/sqlserver-095136-zhs.html Oracle SQL Dev ...

  5. 最有效地优化 Microsoft SQL Server 的性能

      为了最有效地优化 Microsoft SQL Server 的性能,您必须明确当情况不断变化时,性能将在哪些方面得到最大程度的改进,并集中分析这些方面.否则,在这些问题上您可能花费大量的时间和精力 ...

  6. Microsoft SQL Server 管理 (常用管理及维护命令)

    --查询当前连接的实例名 select @@servername --察看任何数据库属性 sp_helpdb master --设置单用户模式,同时立即断开所有用户 alter database No ...

  7. Querying Microsoft SQL Server 2012 读书笔记:查询和管理XML数据 1 -使用FOR XML返回XML结果集

    XML 介绍 <CustomersOrders> <Customer custid="1" companyname="Customer NRZBB&qu ...

  8. SQL Server——存储过程

    我想从下面几个方面大概的讲述下存储过程,可能有些知识点是你没有注意的,也可能有些知识点我不知道,欢迎大家指点指点.如有不足,欢迎指教! 存储过程概念 存储过程优点 存储过程的接口 存储过程的解析.编译 ...

  9. Amazon RDS 上的 Microsoft SQL Server » 导入和导出 SQL Server 数据库

    导入和导出 SQL Server 数据库 Amazon RDS 支持使用完整备份文件 (.bak 文件) 对 Microsoft SQL Server 数据库进行本机备份和还原.您可以在单个便携式文件 ...

随机推荐

  1. Cadence仿真利器,Cadence SI / PI Analysis – Sigrity安装及破解指南

    Sigrity提供了丰富的千兆比特信号与电源网络分析技术,包括面向系统.印刷电路板(PCB)和IC封装设计的独特的考虑电源影响的信号完整性分析功能. Sigrity分析技术与Cadence Alleg ...

  2. CentOS学习笔记—启动、ROOT密码

    启动流程一览 简单来说,系统启动的经过可以汇整成底下的流程的: 加载 BIOS 的硬件资讯与进行自我测试,并依据配置取得第一个可启动的装置: 读取并运行第一个启动装置内 MBR 的 boot Load ...

  3. 【转】CSS white-space 属性

    定义和用法 white-space 属性设置如何处理元素内的空白. 这个属性声明建立布局过程中如何处理元素中的空白符.值 pre-wrap 和 pre-line 是 CSS 2.1 中新增的. 默认值 ...

  4. android开源代码

    Android开源项目--分类汇总 转自:https://github.com/Trinea/android-open-project Android开源项目第一篇——个性化控件(View)篇 包括L ...

  5. 没有Where条件下group by走索引

    C:\Users\Administrator>sqlplus /nolog SQL :: Copyright (c) , , Oracle. All rights reserved. SQL&g ...

  6. 19.python的编码问题

    在正式说明之前,先给大家一个参考资料:戳这里 文章的内容参考了这篇资料,并加以总结,为了避免我总结的不够完善,或者说出现什么错误的地方,有疑问的地方大家可以看看上面那篇文章. 以下说明是针对于pyth ...

  7. 第一步 django的下载安装

    django是python众多web框架中比较有名的一个,以大包大揽功能俱全而著名.但作为重量级的web框架,难免性能上回有所损失,不过由于其封装了各种API,在开发的时候会便利许多.所以也是深受欢迎 ...

  8. 精简配置plsql developer连接oracle

    DB:11.2.0.3.0 OS:oracle-linux 5.7 公司堡垒机为了安全重新规划,各个组只能访问各个组的堡垒机磁盘空间,因此无法访问线上oracle组的磁盘空间,导致plsql deve ...

  9. 向plsql中导入数据

    1.TOOLS-->ODBC IMPORTER 2.TOOLS-->TEXT IMPORTER3.sqlldr userid=zj/zj@orcl control=D:\test.ctl ...

  10. Android--将图片存放到我们本地

    代码里面有详细的解释,我就不多说了 //处理并保存图像 private File dealPhoto(Bitmap photo){ FileOutputStream fileOutputStream ...