dbo.spi_kurs

Description

Properties

Name Value
ANSI Nulls ON

True

Quoted Identifier ON

True

Encrypted

False

Execute As
Assembly

Parameters

Name Data Type Length Description
@datadiff varchar -1

SQL Script

SET QUOTED_IDENTIFIER, ANSI_NULLS ON
GO
CREATE PROCEDURE dbo.spi_kurs
(@datadiff varchar(max))
AS
BEGIN
  declare @datatb table(nomor int, col1 varchar(100), col2 varchar(100))
  if (@datadiff='') 
  begin
 select '01' as msg , 'Data Tidak Ditemukan' as description
 return
  end
  insert into @datatb (
 nomor
 ,col1
 ,col2
  
  )  select row_number() over(order by (select 0)), col1, dbo.trim(replace(col2, ',','.')) from dbo.XQS_ConvertNameValueUStringToTable(@datadiff, ';', '|') 
  

  
  declare @noskep varchar(50)
  set @noskep =  (select top 1 col2 from @datatb where col1 = 'No Skep')
  declare @tgsd varchar(100)
  set @noskep =  (select top 1 col2 from @datatb where col1 = 'No Skep')
  set @tgsd = replace((select top 1 col2 from @datatb  where col1 = 'Periode'), CHAR(32), '')
  declare @tgawal date
  set @tgawal = (CONVERT(date,substring(@tgsd, 7, 4)+'-'+SUBSTRING(@tgsd, 4,2)+'-'+SUBSTRING(@tgsd, 1,2) ) )
  declare @tgakhir date
  set @tgakhir = (CONVERT(date,substring(@tgsd, 20, 4)+'-'+SUBSTRING(@tgsd, 17,2)+'-'+SUBSTRING(@tgsd, 14,2) ) )

BEGIN TRY  
 BEGIN TRANSACTION    
  delete from @datatb where nomor = 1
  delete from @datatb where nomor = 2
  delete from @datatb where nomor = 3
  delete from @datatb where nomor = 4
  insert into [tblKurs] (
  [KdKurs]
      ,[TgAwal]
      ,[TgAkhir]
      ,[Nilai]
      ,[Ket]
  
  ) select 
   dbo.trim(SUBSTRING(col1, 2, 5))
   ,@tgawal
   ,@tgakhir
   ,CAST(col2 as float) 
   ,@noskep
  from @datatb a where not exists (select [TgAwal],  [TgAkhir] from  [tblKurs] t where t.TgAwal = @tgawal and t.TgAkhir=@tgakhir )

COMMIT
END TRY 
BEGIN CATCH
  -- Whoops, there was an error
  IF @@TRANCOUNT > 0
     ROLLBACK

  -- Raise an error with the details of the exception
  DECLARE @ErrMsg nvarchar(4000), @ErrSeverity int
  Set @ErrMsg = ERROR_MESSAGE()
  set @ErrSeverity = ERROR_SEVERITY()
  select @ErrSeverity as status, @ErrMsg as description
  RAISERROR(@ErrMsg, @ErrSeverity, 1)
END CATCH 
  
 select '00' as status , 'SUKSES DOWNLOAD' as description
  
END
--go
--EXEC ('spi_kurs @datadiff=''No Skep|01/KM11/2013|;Tgl Skep|08-01-2013|;Periode|09-01-2013 s/d 15-01-2013|;VALUTA|VALUE (Rp) |;1 USD|9738,0000 |;1 AUD|10195,4500 |;1 BND|7951,3600 |;1 CAD|9860,4600 |;1 CNY|1562,3700 |;1 DKK|1714,1100 |;1 EUR|12789,8800 |;1 HKD|1256,2600 |;1 INR|178,1700 |;1 GBP|15741,2900 |;1 JPY|111,4348 |;1 KRW|9,1600 |;1 KWD|34572,0800 |;1 MYR|3200,5700 |;1 MMK|11,3500 |;1 NOK|1746,2600 |;1 PKR|99,9600 |;1 PHP|238,3600 |;1 SAR|2596,3300 |;1 NZD|8096,6500 |;1 SGD|7952,2700 |;1 LKR|76,4100 |;1 SEK|1494,8400 |;1 CHF|10581,6000 |;1 THB|319,7400 |;'' ')
--go
GO

Used By

No items found