不允许从数据类型datetime到tinyint的隐式转换。使用CONVERT函数运行此查询

时间:2013-11-06 19:00:57

标签: sql-server-2008 tsql sql-server-2008-r2

我理解错误及其含义。我不明白为什么我收到错误,因为我插入的表(表B)是数据来源的表的副本(表A)。你能帮我解释一下我收到错误的原因吗?以下是相关表格的每列的数据类型。

Table A                                    Table B

ID_TYPE:int                            int
ID_TYPE:int                            int
ID_TYPE:int                            int
ID_TYPE:int                            int
ID_TYPE:int                            int
ID_TYPE:int                            int
ID_TYPE:int                            int
ID_TYPE:int                            int
ID_TYPE:int                            int
ID_TYPE:int                            int
ID_TYPE:int                            int
ID_TYPE:int                            int
numeric(19, 4)                         numeric(19, 4)
ID_TYPE:int                            int
numeric(19, 4)                         numeric(19, 4)
ID_TYPE:int                            int
varchar(10)                            varchar(10)
varchar(128)                           varchar(128)
varchar(1000)                          varchar(1000)
ADDRESS_TYPE:varchar(40)               varchar(40)
ADDRESS_TYPE:varchar(40)               varchar(40)
CITY_TYPE:varchar(28)                  varchar(28)
STATE_TYPE:char(2)                     char(2)
POSTALCODE_TYPE:varchar(11)            varchar(11)
NPA_TYPE:varchar(3)                    varchar(3)
NXX_TYPE:varchar(3)                    varchar(3)
LINE_TYPE:varchar(12)                  varchar(12)
smallint                               smallint
varchar(11)                            varchar(11)
datetime                               datetime
datetime                               datetime
varchar(128)                           varchar(128)
varchar(32)                            varchar(32)
BOOLEAN_TYPE:tinyint                   tinyint
BOOLEAN_TYPE:tinyint                   tinyint
varchar(256)                           varchar(256)
varchar(256)                           varchar(256)
varchar(256)                           varchar(256)
datetime                               datetime
BOOLEAN_TYPE:tinyint                   tinyint
ABANO_TYPE:varchar(9)                  varchar(9)
BANKACCTNO_TYPE:varchar(17)            varchar(17)
QBID_TYPE:varchar(36)                  varchar(36)
QBID_TYPE:varchar(36)                  varchar(36)
BOOLEAN_TYPE:tinyint                   tinyint
int                                    int
USERID_TYPE:int                        int
SYSTEMDATE_TYPE:datetime               datetime
USERID_TYPE:int                        int
SYSTEMDATE_TYPE:datetime               datetime
SWORKSTATIONID_TYPE:varchar(256)       varchar(256)
APPLICATIONID_TYPE:smallint            smallint
ID_TYPE:int                            int
ID_TYPE:int                            int
ID_TYPE:int                            int
varchar(128)                           varchar(128)
varchar(128)                           varchar(128)
char(2)                                char(2)
BOOLEAN_TYPE:tinyint                   tinyint
ID_TYPE:int                            int
BOOLEAN_TYPE:tinyint                   tinyint
ID_TYPE:int                            int
BOOLEAN_TYPE:tinyint                   tinyint
varchar(25)                            varchar(25)
                                       nvarchar(50)

查询

 insert into cogent_firm_specific.dbo.client_grouping

 select MAIN.dbo.client.[NCLIENTID]
      ,main.dbo.client.[NFIRMID]
      ,main.dbo.client.[NCLIENTLIASONID]
      ,main.dbo.client.[NPARENTID]
      ,main.dbo.client.[NCLNTCOSTCODEID]
      ,main.dbo.client.[NFEEAGREEMENTID]
      ,main.dbo.client.[NREMITMETHODCODEID]
      ,main.dbo.client.[NCLIENTSTATUSCODEID]
      ,main.dbo.client.[NTRANSACTSTCODEID]
      ,main.dbo.client.[NEXPORTCODEID]
      ,main.dbo.client.[NARCODEID]
      ,main.dbo.client.[NCOLLECTIONCHRGCODEID]
      ,main.dbo.client.[NCOLLCHRG]
      ,main.dbo.client.[NATTYFEECODEID]
      ,main.dbo.client.[NATTYFEE]
      ,main.dbo.client.[NCOUNTRYCODEID]
      ,main.dbo.client.[SCLIENTNO]
      ,main.dbo.client.[SCLIENTNAME]
      ,main.dbo.client.[SCLIENTLEGALNAME]
      ,main.dbo.client.[SADDR1]
      ,main.dbo.client.[SADDR2]
      ,main.dbo.client.[SCITY]
      ,main.dbo.client.[SSTPROV]
      ,main.dbo.client.[SPOSTALCODE]
      ,main.dbo.client.[SCLNTNPA]
      ,main.dbo.client.[SCLNTNXX]
      ,main.dbo.client.[SCLNTLINE]
      ,main.dbo.client.[NPRIORITY]
      ,main.dbo.client.[STIN]
      ,main.dbo.client.[DTLASTPLCMNT]
      ,main.dbo.client.[DTFIRSTPLCMNT]
      ,main.dbo.client.[SWEBSITE]
      ,main.dbo.client.[SWEBLOGIN]
      ,main.dbo.client.[BRPTASFAMILY]
      ,main.dbo.client.[BBILLASFAMILY]
      ,main.dbo.client.[SFTPSITE]
      ,main.dbo.client.[SFTPLOGIN]
      ,main.dbo.client.[SFTPPWD]
      ,main.dbo.client.[DTLASTSTMT]
      ,main.dbo.client.[BNOPOST]
      ,main.dbo.client.[SCLIENTBANKABANO]
      ,main.dbo.client.[SCLIENTBANKACCTNO]
      ,main.dbo.client.[SQBID]
      ,main.dbo.client.[SQBDEBTORID]
      ,main.dbo.client.[BACTIVE]
      ,main.dbo.client.[NCONCURRENCYID]
      ,main.dbo.client.[NCREATEDBY]
      ,main.dbo.client.[DTCREATEDON]
      ,main.dbo.client.[NCHANGEDBY]
      ,main.dbo.client.[DTCHANGEDON]
      ,main.dbo.client.[SWORKSTATIONID]
      ,main.dbo.client.[NAPPLICATIONID]
      ,main.dbo.client.[NCLIENTCODEID]
      ,main.dbo.client.[NENTITYTYPEID]
      ,main.dbo.client.[NPLAINTIFFID]
      ,main.dbo.client.[SDBA]
      ,main.dbo.client.[SFRIENDLYNAME]
      ,main.dbo.client.[SSTINCORPORATEDIN]
      ,main.dbo.client.[BINVOICENSF]
      ,main.dbo.client.[NAUDITORLOGINID]
      ,main.dbo.client.[BALLOWNEGREMIT]
      ,main.dbo.client.[NCREDITORCLASSIFICATIONID]
      ,main.dbo.client.[BRECOVERCOSTSFIRST]
      ,main.dbo.client.[SCOUNTY]
 FROM main.[dbo].CLIENT
  join COGENT_FIRM_SPECIFIC.dbo.Client_Grouping on Client_Grouping.NCLIENTID = client.NCLIENTID 
 where main.dbo.CLIENT.NCLIENTID is null

1 个答案:

答案 0 :(得分:2)

谢谢亚伦。我仍然不确定是什么导致了这个问题,但在()中包含INSERT INTO列列表就可以了。再次感谢!亚伦,请提交答案,我会接受。