首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > SQL Server >

参照昨天一个朋友给的代码,可是出错了,

2012-05-23 
参照昨天一个朋友给的代码,可是出错了,请指教!insert into InterestReceive(CIFNm,RepayType,RepayAmount)

参照昨天一个朋友给的代码,可是出错了,请指教!
insert into InterestReceive(CIFNm,RepayType,RepayAmount)
SELECT CIFNmFROM
(
select CIFNm,ContractNm,LoanBlankDate,PeridNm,'PeriodCapital' as RepayType, PeriodCapital as RepayAmount from InterestList
union all
select CIFNm,ContractNm,LoanBlankDate,PeridNm,'PeriodInterst' as RepayType,PeriodInterst as RepayAmount from InterestList
union all
select CIFNm,ContractNm,LoanBlankDate,PeridNm,'PeriodMangeCharge' as RepayType,PeriodMangeCharge as RepayAmount from InterestList
) T 
where LoanBlankDate=convert(varchar(10),GETDATE(),120)
and not exists (select 1 from InterestReceive b
  where a.CIFNm=b.CIFNm and a.RepayType=b.RepayType and a.RepayAmount=b.RepayAmount)

消息 156,级别 15,状态 1,第 7 行
关键字 'select' 附近有语法错误。
消息 102,级别 15,状态 1,第 12 行
')' 附近有语法错误。

代码是照搬来的,我也读通了,但是就是要出错,怎么的呢

[解决办法]
insert into InterestReceive(CIFNm,RepayType,RepayAmount)
SELECT CIFNm,RepayType,RepayAmount
from(....)


[解决办法]

探讨
insert into InterestReceive(CIFNm,RepayType,RepayAmount)
SELECT CIFNmFROM
(
select CIFNm,ContractNm,LoanBlankDate,PeridNm,'PeriodCapital' as RepayType, PeriodCapital as RepayAmount from InterestLis……

[解决办法]
SELECT CIFNmFROM
-- 改成 SELECT CIFNm,RepayType,RepayAmount FROM 
-- 即查询的字段必须和插入表的字段一一匹配。

[解决办法]
SQL code
insert into InterestReceive(CIFNm,RepayType,RepayAmount)SELECT CIFNm,RepayType,RepayAmount FROM(select CIFNm,ContractNm,LoanBlankDate,PeridNm,'PeriodCapital' as RepayType, PeriodCapital as RepayAmount from InterestListunion allselect CIFNm,ContractNm,LoanBlankDate,PeridNm,'PeriodInterst' as RepayType,PeriodInterst as RepayAmount from InterestListunion allselect CIFNm,ContractNm,LoanBlankDate,PeridNm,'PeriodMangeCharge' as RepayType,PeriodMangeCharge as RepayAmount from InterestList) AS a where LoanBlankDate = convert(varchar(10),GETDATE(),120)and not exists (select 1 from InterestReceive AS b  where a.CIFNm=b.CIFNm and a.RepayType=b.RepayType and a.RepayAmount=b.RepayAmount) 

热点排行