这个查询只能有一个值
(select convert(varchar(8),b.c_senddate,112) from csrk.dbo.tab_csz as b  where c.cb_birthno=b.c_sendcard) as CARD_TIME看语句的意思,应该是查一个时间,你可以设定要查最大时间
(select convert(varchar(8),MAX(b.c_senddate),112) from csrk.dbo.tab_csz as b  where c.cb_birthno=b.c_sendcard) as CARD_TIME
或最小时间
(select convert(varchar(8),MIN(b.c_senddate),112) from csrk.dbo.tab_csz as b  where c.cb_birthno=b.c_sendcard) as CARD_TIME
这样子查询就确保只有一个了

解决方案 »

  1.   

    可以用top的:insert into T_PH_BIRTHCERTIFICATE_CERTIFICATE
    (SOURCE_RECORD_ID,LOCAL_ORG_ID,ACCESS_SYSTEM_ID,ORIGINAL_ID,
    BIRTH_CARD_ID,CARD_TIME,CARD_ORG_CODE,CARD_ORG_NAME)
    select 
    c.cb_id as SOURCE_RECORD_ID,
    c.cb_fazhengunit as LOCAL_ORG_ID,
    'HNBCS' as ACCESS_SYSTEM_ID,
    c.cb_id as ORIGINAL_ID,
    c.cb_birthno as BIRTH_CARD_ID,
    (select top 1 convert(varchar(8),b.c_senddate,112) from csrk.dbo.tab_csz as b  where c.cb_birthno=b.c_sendcard) as CARD_TIME,
    c.cb_fazhengunit CARD_ORG_CODE,
    c.cb_fazhengunitname CARD_ORG_NAME
    from csrk.dbo.hospitaldata as h left join csrk.dbo.childbirthdata as c on h.hd_id = c.cb_id 
    where c.cb_birthno <> '' and h.hd_inputday between '20130101' and '20141231'
    and hd_motheridno <> '' and hd_mothertype='身份证'