You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
sql-tools/ImportBK/导BOKA_2_在A8数据库执行.sql

837 lines
16 KiB

1 year ago
--<EFBFBD><EFBFBD>A8<EFBFBD><EFBFBD><EFBFBD>ݿ<EFBFBD>,ִ<EFBFBD>д˽ű<EFBFBD>
--<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݿ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
--if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#ImportConfig'))
IF object_id('TImportConfig#') IS NOT NULL
BEGIN
DROP TABLE TImportConfig#
END
GO
CREATE TABLE TImportConfig#
(
FFromServer VARCHAR(200),
FFromDatabase VARCHAR(200),
FToServer VARCHAR(200),
FToDatabase VARCHAR(200)
)
GO
--------------------------------------------------
--<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ID
--------------------------------------------------
IF object_id('dbo.FNNewId') IS NOT NULL
BEGIN
DROP FUNCTION dbo.FNNewId
END
GO
CREATE FUNCTION FNNewId()
RETURNS VARCHAR(40)
AS
BEGIN
DECLARE @Id BIGINT
SELECT @Id = Id FROM VNewId
RETURN @Id
END
GO
--------------------------------------------------
--<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ID
--------------------------------------------------
if exists (select 1
from sysobjects
where id = object_id('VNewId')
and type = 'V')
drop view VNewId
GO
create view VNewId as
SELECT Id = abs( CAST( CAST(newid() AS BINARY(16)) AS BIGINT))
GO
IF object_id('dbo.FNGetFirstPinYin') IS NOT NULL
BEGIN
DROP FUNCTION dbo.FNGetFirstPinYin
END
GO
--------------------------------------------------
--<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ƴ<EFBFBD><EFBFBD>
--------------------------------------------------
CREATE FUNCTION FNGetFirstPinYin(@chinese varchar(1024))
RETURNS varchar(1024)
AS
BEGIN
declare @strlen int,@return varchar(500),@ii int
declare @n int,@c char(1),@chn nchar(1)
select @strlen=len(@chinese),@return='',@ii=0
set @ii=0
while @ii<@strlen
begin
select @ii=@ii+1,@n=63,@chn=substring(@chinese,@ii,1)
if @chn>'z'
begin
select @n = @n +1,
@c = case chn when @chn then char(@n) else @c end
from
(select top 27 * from
(select chn = '߹'
union all select '<EFBFBD><EFBFBD>'
union all select '<EFBFBD><EFBFBD>'
union all select '<EFBFBD><EFBFBD>'
union all select '<EFBFBD><EFBFBD>'
union all select '<EFBFBD><EFBFBD>'
union all select '<EFBFBD><EFBFBD>'
union all select '<EFBFBD><EFBFBD>'
union all select 'آ' --because have no 'i'
union all select 'آ'
union all select '<EFBFBD><EFBFBD>'
union all select '<EFBFBD><EFBFBD>'
union all select '<EFBFBD>`'
union all select '<EFBFBD><EFBFBD>'
union all select '<EFBFBD><EFBFBD>'
union all select '<EFBFBD>r'
union all select '<EFBFBD><EFBFBD>'
union all select '<EFBFBD><EFBFBD>'
union all select '<EFBFBD><EFBFBD>'
union all select '<EFBFBD><EFBFBD>'
union all select '<EFBFBD><EFBFBD>' --no 'u'
union all select '<EFBFBD><EFBFBD>' --no 'v'
union all select '<EFBFBD><EFBFBD>'
union all select 'Ϧ'
union all select 'Ѿ'
union all select '<EFBFBD><EFBFBD>'
union all select @chn) as a
order by chn COLLATE Chinese_PRC_CI_AS ) as b
end
else
begin
set @c=@chn
end
set @return=@return+@c
end
return(@return)
END
GO
--ת<EFBFBD><EFBFBD>ID
IF object_id('dbo.FNBKId') IS NOT NULL
BEGIN
DROP FUNCTION dbo.FNBKId
END
GO
CREATE FUNCTION FNBKId
(
@Value varchar(5)
)
RETURNS BIGINT
BEGIN
RETURN cast(cast(@Value as binary(8)) as bigint)
END
GO
--ת<EFBFBD><EFBFBD><EFBFBD><EFBFBD>˾ID
IF object_id('dbo.FNBKCompId') IS NOT NULL
BEGIN
DROP FUNCTION dbo.FNBKCompId
END
GO
CREATE FUNCTION FNBKCompId
(
@Value varchar(5)
)
RETURNS BIGINT
BEGIN
IF @Value = '001'
RETURN 1
RETURN dbo.FNBKid(@Value);
END
GO
--ת<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
IF object_id('dbo.FNBKDate') IS NOT NULL
BEGIN
DROP FUNCTION dbo.FNBKDate
END
GO
CREATE FUNCTION FNBKDate
(
@FmtDate varchar(10)
)
RETURNS DATETIME
BEGIN
IF CHARINDEX('-',@FmtDate) > -1
RETURN @FmtDate
IF @FmtDate IS NULL OR ISNULL(@FmtDate,'') = '' OR (LEN(@FmtDate) != 8 AND LEN(@FmtDate) != 4) OR @FMTDATE = '000000'
BEGIN
RETURN NULL
END
IF LEN(@FmtDate) = 4
BEGIN
SELECT @FmtDate = '9999' + @FmtDate
END
DECLARE @Year VARCHAR(4)
DECLARE @Month VARCHAR(2)
DECLARE @Day VARCHAR(2)
SELECT @Year = LEFT(@FmtDate,4),@Month = SUBSTRING(@FmtDate,5,2),@Day = RIGHT(@FmtDate,2)
IF @Year < '1753'
BEGIN
SELECT @Year = '9999'
END
IF @Month < '01' OR @Month > '12' OR @Day < '01' OR @Day > '31'
BEGIN
RETURN NULL
END
IF @Day > '30' AND @Month IN('04','06','09','11')
BEGIN
SET @Day = '30'
END
--IF @Month = '02' AND @Day = '29'
--BEGIN
-- print ''-- SET @Year = '2000'
--END
select @FmtDate = @Year + '-' + @Month + '-' + @Day
return @FmtDate
END
GO
--ת<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
IF object_id('dbo.FNBKBirthday') IS NOT NULL
BEGIN
DROP FUNCTION dbo.FNBKBirthday
END
GO
CREATE FUNCTION FNBKBirthday
(
@FmtDate varchar(10)
)
RETURNS DATETIME
BEGIN
SET @FmtDate = REPLACE(@FmtDate,' ','')
IF ISNULL(@FmtDate,'') = '' OR (LEN(@FmtDate) != 8 AND LEN(@FmtDate) != 4) OR @FMTDATE = '00000000' OR @FMTDATE = '0000'
BEGIN
RETURN NULL
END
IF LEN(@FmtDate) = 4
BEGIN
SELECT @FmtDate = '9999' + @FmtDate
END
IF LEFT(@FmtDate,4) = '0000'
BEGIN
SELECT @FmtDate = REPLACE(@FmtDate,'0000','9999')
END
DECLARE @Year VARCHAR(4)
DECLARE @Month VARCHAR(2)
DECLARE @Day VARCHAR(2)
SELECT @Year = LEFT(@FmtDate,4),@Month = SUBSTRING(@FmtDate,5,2),@Day = RIGHT(@FmtDate,2)
IF @Year < '1753'
BEGIN
SELECT @Year = '9999'
END
IF @Month < '01' OR @Month > '12' OR @Day < '01' OR @Day > '31'
BEGIN
RETURN NULL
END
IF @Day > '30' AND @Month IN('04','06','09','11')
BEGIN
SET @Day = '30'
END
IF @Month = '02' AND @Day >= '29'
BEGIN
SET @Day = '29'
IF @Year % 4 != 0
SET @Day = '28'
END
select @FmtDate = @Year + '-' + @Month + '-' + @Day
return @FmtDate
END
GO
--ת<EFBFBD><EFBFBD>ʱ<EFBFBD><EFBFBD>
IF object_id('dbo.FNBKTime') IS NOT NULL
BEGIN
DROP FUNCTION dbo.FNBKTime
END
GO
CREATE FUNCTION FNBKTime
(
@FmtDate varchar(1000),
@FmtTime varchar(1000)
)
RETURNS DATETIME
BEGIN
IF ISNULL(@FmtDate,'') = '' OR LEN(@FmtDate) != 8
BEGIN
RETURN NULL
END
DECLARE @Year VARCHAR(4)
DECLARE @Month VARCHAR(2)
DECLARE @Day VARCHAR(2)
SELECT @Year = LEFT(@FmtDate,4),@Month = SUBSTRING(@FmtDate,5,2),@Day = RIGHT(@FmtDate,2)
IF @Year < '1753'
BEGIN
SELECT @Year = '1753'
END
IF @Month = '02' AND @Day = '29' AND @Year % 4 != 0
BEGIN
SET @Day = '28'
END
IF @Month < '01' OR @Month > '12' OR @Day < '01' OR @Day > '31'
BEGIN
RETURN NULL
END
select @FmtDate = @Year + '-' + @Month + '-' + @Day
IF ISNULL(@FmtTime,'') = '' OR LEN(@FmtTime) != 6
BEGIN
SET @FmtTime = '120000'
END
select @FmtDate = @FmtDate + ' ' + LEFT(@FmtTime,2) + ':' + SUBSTRING(@FmtTime,3,2) + ':' + RIGHT(@FmtTime,2)
return @FmtDate
END
GO
--ת<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD>ʽ
IF object_id('dbo.FNBKPointMode') IS NOT NULL
BEGIN
DROP FUNCTION dbo.FNBKPointMode
END
GO
CREATE FUNCTION FNBKPointMode
(
@Value varchar(1)
)
RETURNS INT
BEGIN
IF ISNULL(@Value,'') = ''
BEGIN
RETURN 0
END
RETURN CASE @Value
WHEN '1' THEN 1 --<EFBFBD>̶<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
WHEN '2' THEN 2 --Ӫҵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
WHEN '3' THEN 7 --Ӫҵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
WHEN '4' THEN 3 --ʵ<EFBFBD><EFBFBD>Ӫҵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
ELSE 0 END
END
GO
--<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
IF object_id('dbo.FNBKBillType') IS NOT NULL
BEGIN
DROP FUNCTION dbo.FNBKBillType
END
GO
CREATE FUNCTION FNBKBillType
(
@Value varchar(20)
)
RETURNS VARCHAR(30)
BEGIN
return 11
END
GO
--<EFBFBD>˻<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
IF object_id('dbo.FNBKAcctOper') IS NOT NULL
BEGIN
DROP FUNCTION dbo.FNBKAcctOper
END
GO
CREATE FUNCTION FNBKAcctOper
(
@Value varchar(20)
)
RETURNS VARCHAR(30)
BEGIN
IF @Value = '0'
BEGIN
return '<EFBFBD><EFBFBD>ֵ'
END
ELSE IF @Value = '1'
BEGIN
RETURN 'ȡ<EFBFBD><EFBFBD>'
END
ELSE IF @Value = '2'
BEGIN
RETURN '<EFBFBD><EFBFBD><EFBFBD><EFBFBD>'
END
ELSE IF @Value = '5'
BEGIN
RETURN 'Ƿ<EFBFBD><EFBFBD>'
END
ELSE IF @Value = '6'
BEGIN
RETURN 'Ƿ<EFBFBD><EFBFBD><EFBFBD>'
END
RETURN ''
END
GO
--<EFBFBD><EFBFBD>Ŀҵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʽ
IF object_id('dbo.FNBKItemPerfMode') IS NOT NULL
BEGIN
DROP FUNCTION dbo.FNBKItemPerfMode
END
GO
CREATE FUNCTION FNBKItemPerfMode
(
@Value INT
)
RETURNS VARCHAR(30)
BEGIN
RETURN
CASE @Value
WHEN 1 THEN 1 --<EFBFBD>̶<EFBFBD>
WHEN 2 THEN 2 --Ӫҵ<EFBFBD><EFBFBD>
WHEN 5 THEN 7 --<EFBFBD><EFBFBD>׼<EFBFBD><EFBFBD>
WHEN 9 THEN 3 --ʵ<EFBFBD>ն<EFBFBD>
WHEN 6 THEN 202--Ӫҵ<EFBFBD><EFBFBD><EFBFBD>۵ڶ<EFBFBD><EFBFBD><EFBFBD>
WHEN 7 THEN 203--Ӫҵ<EFBFBD><EFBFBD><EFBFBD>۵<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
WHEN 8 THEN 205--Ӫҵ<EFBFBD><EFBFBD><EFBFBD>۶<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
WHEN 61 THEN 302--ʵ<EFBFBD>ն<EFBFBD><EFBFBD>۶<EFBFBD><EFBFBD><EFBFBD>
WHEN 71 THEN 303--ʵ<EFBFBD>ն<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
WHEN 81 THEN 305--ʵ<EFBFBD>ն<EFBFBD><EFBFBD>۶<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
WHEN 62 THEN 212--ʵ<EFBFBD>ն<EFBFBD><EFBFBD>ȿ۶<EFBFBD><EFBFBD><EFBFBD>
WHEN 72 THEN 213--ʵ<EFBFBD>ն<EFBFBD><EFBFBD>ȿ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
WHEN 82 THEN 215--ʵ<EFBFBD>ն<EFBFBD><EFBFBD>ȿ۶<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
ELSE 0 END
END
GO
--<EFBFBD><EFBFBD><EFBFBD>ɷ<EFBFBD>ʽ
IF object_id('dbo.FNBKItemCommMode') IS NOT NULL
BEGIN
DROP FUNCTION dbo.FNBKItemCommMode
END
GO
CREATE FUNCTION FNBKItemCommMode
(
@Value INT
)
RETURNS VARCHAR(30)
BEGIN
RETURN
CASE @Value
WHEN 1 THEN 1 --<EFBFBD>̶<EFBFBD>
WHEN 2 THEN 2 --Ӫҵ<EFBFBD><EFBFBD>
WHEN 3 THEN 5 --<EFBFBD>۳ɱ<EFBFBD>
WHEN 4 THEN 4 --ҵ<EFBFBD><EFBFBD>
WHEN 41 THEN 6 --ʵ<EFBFBD><EFBFBD>ҵ<EFBFBD><EFBFBD>
WHEN 5 THEN 7 --<EFBFBD><EFBFBD>׼<EFBFBD><EFBFBD>
WHEN 7 THEN 333 --ʵ<EFBFBD>ն<EFBFBD>_<EFBFBD>۵<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
WHEN 8 THEN 335 --ʵ<EFBFBD>ն<EFBFBD>_<EFBFBD>۵ڶ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
WHEN 9 THEN 332 --ʵ<EFBFBD>ն<EFBFBD>_<EFBFBD>۵ڶ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
WHEN 90 THEN 433 --ҵ<EFBFBD><EFBFBD>_<EFBFBD>۵<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
WHEN 91 THEN 435 --ҵ<EFBFBD><EFBFBD>_<EFBFBD>۵ڶ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
WHEN 92 THEN 432 --ҵ<EFBFBD><EFBFBD>_<EFBFBD>۵ڶ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
WHEN 93 THEN 533 --ʵ<EFBFBD>ն<EFBFBD>_<EFBFBD>۵<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
WHEN 94 THEN 535 --ʵ<EFBFBD>ն<EFBFBD>_<EFBFBD>۵ڶ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
WHEN 95 THEN 532 --ʵ<EFBFBD>ն<EFBFBD>_<EFBFBD>۵ڶ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
ELSE 4 END
END
GO
--<EFBFBD><EFBFBD>Ŀ<EFBFBD>ɱ<EFBFBD><EFBFBD><EFBFBD>ʽ
IF object_id('dbo.FNBKItemCostMode') IS NOT NULL
BEGIN
DROP FUNCTION dbo.FNBKItemCostMode
END
GO
CREATE FUNCTION FNBKItemCostMode
(
@Value INT
)
RETURNS VARCHAR(30)
BEGIN
RETURN
CASE @Value
WHEN 1 THEN 2 --Ӫҵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
WHEN 2 THEN 7 --ԭ<EFBFBD><EFBFBD>
WHEN 3 THEN 1 --<EFBFBD>̶<EFBFBD>
WHEN 4 THEN 11 --<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>IJ<EFBFBD>Ʒ<EFBFBD>ijɱ<EFBFBD>
WHEN 7 THEN 3 --ʵ
ELSE 0 END
END
GO
--<EFBFBD><EFBFBD>Ʒҵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʽ
IF object_id('dbo.FNBKGoodsPerfMode') IS NOT NULL
BEGIN
DROP FUNCTION dbo.FNBKGoodsPerfMode
END
GO
CREATE FUNCTION FNBKGoodsPerfMode
(
@Value INT
)
RETURNS VARCHAR(30)
BEGIN
RETURN
CASE @Value
WHEN 1 THEN 1 --<EFBFBD>̶<EFBFBD>
WHEN 2 THEN 2 --Ӫҵ<EFBFBD><EFBFBD>
WHEN 10 THEN 2 -- Ӫҵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ۿ<EFBFBD>
WHEN 11 THEN 2 -- ʵ<EFBFBD><EFBFBD>Ӫҵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ۿ<EFBFBD>
WHEN 20 THEN 7 -- <EFBFBD><EFBFBD>׼<EFBFBD><EFBFBD>-<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɱ<EFBFBD>
WHEN 21 THEN 2 -- Ӫҵ<EFBFBD><EFBFBD>-<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɱ<EFBFBD>
WHEN 22 THEN 7 -- <EFBFBD><EFBFBD>׼<EFBFBD><EFBFBD>-<EFBFBD><EFBFBD><EFBFBD>۳ɱ<EFBFBD>
WHEN 23 THEN 2 -- Ӫҵ<EFBFBD><EFBFBD>-<EFBFBD><EFBFBD><EFBFBD>۳ɱ<EFBFBD>
WHEN 5 THEN 7 -- <EFBFBD><EFBFBD>׼<EFBFBD>۱<EFBFBD><EFBFBD><EFBFBD>
WHEN 9 THEN 3 -- ʵ<EFBFBD><EFBFBD>Ӫҵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
ELSE 2 END
END
GO
--<EFBFBD><EFBFBD>Ʒ<EFBFBD><EFBFBD><EFBFBD>ɷ<EFBFBD>ʽ
IF object_id('dbo.FNBKGoodsCommMode') IS NOT NULL
BEGIN
DROP FUNCTION dbo.FNBKGoodsCommMode
END
GO
CREATE FUNCTION FNBKGoodsCommMode
(
@Value INT
)
RETURNS VARCHAR(30)
BEGIN
RETURN
CASE @Value
WHEN 1 THEN 1 --<EFBFBD>̶<EFBFBD>
WHEN 2 THEN 5 --Ӫҵ<EFBFBD><EFBFBD>
WHEN 3 THEN 5 --<EFBFBD>۳ɱ<EFBFBD>
WHEN 4 THEN 5 --ҵ<EFBFBD><EFBFBD>
WHEN 41 THEN 6 --ʵ<EFBFBD><EFBFBD>ҵ<EFBFBD><EFBFBD>
WHEN 5 THEN 7 --<EFBFBD><EFBFBD>׼<EFBFBD><EFBFBD>
ELSE 2 END
END
GO
--<EFBFBD><EFBFBD>ֵ<EFBFBD><EFBFBD>ҵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʽ
IF object_id('dbo.FNBKCardPerfMode') IS NOT NULL
BEGIN
DROP FUNCTION dbo.FNBKCardPerfMode
END
GO
CREATE FUNCTION FNBKCardPerfMode
(
@Value INT
)
RETURNS VARCHAR(30)
BEGIN
RETURN
CASE @Value
WHEN 1 THEN 1 --<EFBFBD>̶<EFBFBD>
WHEN 2 THEN 3 --Ӫҵ<EFBFBD><EFBFBD>
WHEN 10 THEN 2 -- Ӫҵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ۿ<EFBFBD>
WHEN 11 THEN 2 -- ʵ<EFBFBD><EFBFBD>Ӫҵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ۿ<EFBFBD>
WHEN 5 THEN 7 -- <EFBFBD><EFBFBD>׼<EFBFBD>۱<EFBFBD><EFBFBD><EFBFBD>
WHEN 9 THEN 3 -- ʵ<EFBFBD><EFBFBD>Ӫҵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
ELSE 2 END
END
GO
--<EFBFBD><EFBFBD>ֵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɷ<EFBFBD>ʽ
IF object_id('dbo.FNBKCardCommMode') IS NOT NULL
BEGIN
DROP FUNCTION dbo.FNBKCardCommMode
END
GO
CREATE FUNCTION FNBKCardCommMode
(
@Value INT
)
RETURNS VARCHAR(30)
BEGIN
RETURN
CASE @Value
WHEN 1 THEN 1 --<EFBFBD>̶<EFBFBD>
WHEN 2 THEN 4 --Ӫҵ<EFBFBD><EFBFBD>
WHEN 3 THEN 4 --<EFBFBD>۳ɱ<EFBFBD>
WHEN 4 THEN 4 --ҵ<EFBFBD><EFBFBD>
WHEN 41 THEN 6 --ʵ<EFBFBD><EFBFBD>ҵ<EFBFBD><EFBFBD>
WHEN 5 THEN 7 --<EFBFBD><EFBFBD>׼<EFBFBD><EFBFBD>
ELSE 2 END
END
GO
--<EFBFBD><EFBFBD>Ա<EFBFBD><EFBFBD>״̬
IF object_id('dbo.FNBkCardState') IS NOT NULL
BEGIN
DROP FUNCTION dbo.FNBkCardState
END
GO
CREATE FUNCTION FNBkCardState
(
@Value INT
)
RETURNS VARCHAR(30)
BEGIN
RETURN
CASE @Value
WHEN 1 THEN 0 --δ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
WHEN 10 THEN 1 --<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
WHEN 2 THEN 0 --<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
WHEN 3 THEN 0 --<EFBFBD><EFBFBD>ע<EFBFBD><EFBFBD>
WHEN 4 THEN 1 --<EFBFBD>ѿ<EFBFBD><EFBFBD><EFBFBD>
WHEN 5 THEN 1 --<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʹ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
WHEN 6 THEN 3 --<EFBFBD><EFBFBD>ת<EFBFBD><EFBFBD>
WHEN 7 THEN 2 --<EFBFBD><EFBFBD><EFBFBD>˿<EFBFBD>
WHEN 8 THEN 1 --<EFBFBD>ѹ<EFBFBD><EFBFBD><EFBFBD>
WHEN 9 THEN 16 --<EFBFBD>ѹ<EFBFBD>ʧ
ELSE 0 END
END
GO
--<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʷ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
IF object_id('dbo.FNBKTransBizType') IS NOT NULL
BEGIN
DROP FUNCTION dbo.FNBKTransBizType
END
GO
CREATE FUNCTION FNBKTransBizType
(
@Value varchar(20)
)
RETURNS VARCHAR(30)
BEGIN
IF @Value = '1'
BEGIN
return 'DR.CardSale'
END
ELSE IF @Value = '2'
BEGIN
RETURN 'DR.CourseSale'
END
ELSE IF @Value = '7' OR @Value = '8'
BEGIN
RETURN 'DR.CoursePackSale'
END
ELSE IF @Value = '5'
BEGIN
RETURN 'DR.CardRchg'
END
ELSE IF @Value = '3'
BEGIN
RETURN 'DR.Item'
END
ELSE IF @Value = '4'
BEGIN
RETURN 'DR.Goods'
END
RETURN 'DR'
END
GO
--ִ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
IF object_id('dbo.PBKBuildSQL','P') IS NOT NULL
BEGIN
DROP PROCEDURE dbo.PBKBuildSQL
END
GO
CREATE PROCEDURE PBKBuildSQL
(
@InSql VARCHAR(8000),
@OutSql VARCHAR(8000) OUTPUT
)
AS
BEGIN
DECLARE @FromServer VARCHAR(200),
@FromDatabase VARCHAR(200),
@ToServer VARCHAR(200),
@ToDatabase VARCHAR(200)
SELECT @FromServer = FFromServer,
@FromDatabase = FFromDatabase,
@ToServer = FToServer,
@ToDatabase = FToDatabase
FROM TImportConfig#
IF ISNULL(@FromDatabase,'') = '' OR ISNULL(@FromDatabase,'') = ''
BEGIN
RAISERROR ('<EFBFBD><EFBFBD><EFBFBD>ò<EFBFBD><EFBFBD><EFBFBD>ȷ' , 16, 1, 1, 1, 1)
RETURN
END
SELECT @InSql = REPLACE(@InSql,' ',' ')
SELECT @InSql = REPLACE(@InSql,' ',' ')
SELECT @InSql = REPLACE(@InSql,' ',' ')
DECLARE @From VARCHAR(200)
SELECT @From = @FromDatabase + '.dbo'
IF ISNULL(@FromServer,'') != ''
BEGIN
SELECT @From = @FromServer + '.' + @From
END
DECLARE @To VARCHAR(200)
SELECT @To = @ToDatabase + '.dbo'
IF ISNULL(@ToServer,'') != ''
BEGIN
SELECT @To = @ToServer + '.' + @To
END
SET @OutSql = REPLACE(@InSql,'{FDB}',@From);
SET @OutSql = REPLACE(@OutSql,'{TDB}',@To);
END
GO
--ִ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
IF object_id('dbo.PExecImportSQL','P') IS NOT NULL
BEGIN
DROP PROCEDURE dbo.PExecImportSQL
END
GO
CREATE PROCEDURE PExecImportSQL
(
@Sql VARCHAR(8000),
@Sql2 VARCHAR(8000) = ''
)
AS
BEGIN
EXEC PBKBuildSQL @Sql,@Sql OUTPUT
IF @Sql2 != ''
BEGIN
EXEC PBKBuildSQL @Sql2,@Sql2 OUTPUT
END
--EXEC ('USE ' + @ToDatabase)
EXEC (@Sql +@Sql2 )
END
GO
--<EFBFBD><EFBFBD>ʼ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
IF object_id('dbo.PInitConnection','P') IS NOT NULL
BEGIN
DROP PROCEDURE dbo.PInitConnection
END
GO
CREATE PROCEDURE PInitConnection
(
@FromServer VARCHAR(1024),
@FromDatabase VARCHAR(200),
@FromUser VARCHAR(1024),
@FromPassword VARCHAR(1024),
-- @ToServer VARCHAR(1024),
@ToDatabase VARCHAR(200)--,
-- @ToUser VARCHAR(1024),
-- @ToPassword VARCHAR(1024)
)
AS
BEGIN
IF ISNULL(@FromServer,'') != ''
BEGIN
if exists(select 1 from master..sysservers where srvname='fromServer')
begin
exec sp_dropserver 'fromServer','droplogins'
end
exec sp_addlinkedserver 'fromServer','','SQLOLEDB',@FromServer
exec sp_addlinkedsrvlogin 'fromServer','false',null,@FromUser,@FromPassword
END
/* IF ISNULL(@ToServer,'') != ''
BEGIN
if exists(select 1 from master..sysservers where srvname='toServer')
begin
exec sp_dropserver 'toServer','droplogins'
end
exec sp_addlinkedserver 'toServer','','SQLOLEDB',@ToServer
exec sp_addlinkedsrvlogin 'toServer','false',null,@ToUser,@ToPassword
END*/
/*IF @FromDatabase = @ToDatabase
BEGIN
RAISERROR ('<EFBFBD><EFBFBD><EFBFBD>ݿⲻ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͬ' , 16, 1, 1, 1, 1)
RETURN
END*/
DELETE TImportConfig#
INSERT TImportConfig#(FFromServer,FFromDatabase,FToServer,FToDatabase)
VALUES ('fromServer',@FromDatabase,'',@ToDatabase)
END
GO