-- 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. POJ C++程序设计 编程题#1 编程作业—运算符重载

    编程题 #2 来源: POJ (Coursera声明:在POJ上完成的习题将不会计入Coursera的最后成绩.) 注意: 总时间限制: 1000ms 内存限制: 65536kB 描述 下面的MyIn ...

  2. C#访问配置文件

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.R ...

  3. varnish状态引擎2

    如何让varnish支持虚拟主机: if (req.http.host = "www.nihao.com") { } 强制对某资源的请求,不检查缓存: 上图表示以/test1.ht ...

  4. delphi的多线程编程

    多线程的基本概念 win 98/nt/2000/xp 是个多任务操作系统,也就是:一个进程可以划分为多个线程,每个线程轮流占用cpu 运行时间和资源,或者说,把cpu 时间划成片,每个片分给不同的线程 ...

  5. 清空FORM表单的几种方式 Reset 重加载

    1. form中定义name <form name = "sbform" action="sb_add.php" method="post&qu ...

  6. LinearRegressionWithRegularization

    在线性回归的基础上加上正则项: # -*-coding:utf-8 -*- ''' Created on 2016年12月15日 @author: lpworkdstudy ''' import nu ...

  7. throw和throws

    uncheckException的处理 class User{ private int age; public void setAge(int age){ if(age < 0){ //生成异常 ...

  8. java读取各类型的文件

    java读取各类型的文件 用到的几个包 bcmail-jdk14-132.jar/bcprov-jdk14-132.jar/checkstyle-all-4.2.jar/FontBox-0.1.0-d ...

  9. Sqlserver中char,nchar,varchar与Nvarchar的区别分析

    1. char类型: 对英文(ASCII)字符占用1个字节,对一个汉字占用2个字节,CHAR存储定长数据很方便,CHAR字段上的索引效率极高,比如定义char(10),那么不论你存储的数据是否达 到了 ...

  10. IE浏览器各版本的CSS Hack

    IE浏览器各版本的CSS   Hack 如下示例: .test{ color:black;/*W3C*/ color:red\9;/* IE6-IE10 */ _color:black;/*IE6*/ ...