-- 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. Oracle数据库中的Function调用参数问题

    在工作中用到了Oracle数据库,需要调用Oracle的Function,Function返回的游标和结果都是通过参数来获取的 比如Function定义如下: , intype, ininttype) ...

  2. Operation is not valid due to the current state of the object.

    今天遇到一个asp.net的草郁闷的问题,看下截图 狂晕啊,在google上狂搜了一下,好在已经有大侠也遇到过这个问题了,先看下别人的解决办法吧 Operation is not valid due ...

  3. JQ定义

    什么是jQuery对象 通过$(‘选择器’)获取到都是jQuery对象 什么是DOM对象 通过getElementById或者 getElementsByTagName或者getElementsByN ...

  4. jquery ajax跨域请求详解

    本文章来给大家详细jquery中的ajax跨域请求, 在JQuery对于Ajax的跨域请求有两类解决方案,不过都是只支持get方式.分别是JQuery的jquery.ajax jsonp格式和jque ...

  5. CentOS6.4安装VNC

    http://jingyan.baidu.com/article/ca2d939dd1dabbeb6c31ce24.html 一.安装 VNC 默认情况下,CentOS 6.4 是没有安装的. 检查是 ...

  6. .NET开源工作流RoadFlow-流程设计-流程步骤设置-数据设置

    数据设置是控制在流程处理过程中,当前步骤的数据显示与编辑状态,控制当前步骤哪些字段为只读,隐藏或可编辑.需要配合表单设计器使用.

  7. ORACLE 分区表简介

    参考链接:http://blog.csdn.net/ziwen00/article/details/9158725ORACLE-分区表 此文从以下几个方面来整理关于分区表的概念及操作: 1.表空间及分 ...

  8. 源码解析之setContentView

    分享一下我以前学习时做到PPT中的一部分. 不难看出其实设置布局是由PhoneWindow来完成的. 然而我们要记住DecorView: 包括:状态栏,标题栏,内容 phoneWindow -> ...

  9. 关于table元素的认识

    表格是网页上最常见的元素,但是,现在对很多刚入行的前端们那是谈table色变.那是为啥?这是表格的框架的简单.明了.在传统的网页中使用没有边框的表格来排版是非常流行.在web标准逐渐深入设计领域以后, ...

  10. 引用类型a=b

    List<int> list = new List<int>(); list.Add(1); list.Add(2); list.Add(3); Cache["Key ...