-- 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. IOS中获取屏幕尺寸

    //app尺寸,去掉状态栏 CGRect appRect = [UIScreen mainScreen].applicationFrame; NSLog(@"%f, %f, %f,%f&qu ...

  2. PeopleCode 处理压缩文件

     PeopleSoft中对文件附件的处理都是单个文件处理的,虽然在8.52版本新增了MAddAttachment(URLDestination, DirAndFilePrefix, Prompts, ...

  3. MongoDB(3):小的细节问题

    1.文档 {“greeting”:“hello,world”,“foo”: 3} 文档中的键/值对是有序的,下面的文档与上面的文档是完全不同的两个文档. {“foo”: 3 ,“greeting”:“ ...

  4. [IIS] eset/Restart/Recycling/Refresh 的区别

    iisreset -- 对象是整个IIS服务器,这个操作会先停止万维网的服务(World Wide Web Publishing Service)然后在重启此服务,因此所有的网站都会先停止服务然后在重 ...

  5. UltraEdit中使用正则表达式

    正则表达式 (UltraEdit Syntax): % 匹配行首 - 表明要搜索的字符串一定在行首. $ 匹配行尾 - 表明要搜索的字符串一定在行尾 ? 匹配除换行符外的任一单个字符. * 匹配任意个 ...

  6. VM虚拟机无法拖拽、粘贴、复制

    VM无法从客户机拖放/复制文件到虚拟机的解决办法: 将这两项取消勾选,点击[确定].再次打开,勾选,点击[确定] 原因分析:可能是VM中默认是不支持该功能的,但是在配置窗体上确实默认打钩打上的. 依据 ...

  7. Ztack学习笔记(6)-广播组播点播

    Zigbee网络中进行数据通信主要有三种类型:单播.组播.广播.那这三种方式如何设置呢,在哪里设置呢, 一. 广播 当应用程序需要将数据包发送给网络的每一个设备时,使用这种模式.广播的短地址有三种 0 ...

  8. java的软件包

    Java的软件包:简单来说,软件包就是把类放在不同的文件夹下,提供了命名空间 package wang; //用package将Test类放在wang文件下 class Test{ public st ...

  9. net-snmp的安装

    安装环境是ubuntu 14. 方法1:apt-get install  net-snmp (非root用户需要sudo 提升权限) 方法2:自定义安装选择不同的版本去编译. 1:先去下载所需要的ta ...

  10. 为SM30视图分配事务代码

    Tcode:SE93