SQL Server:查询联合所有转换类型失败

时间:2015-04-06 18:59:42

标签: sql-server

我正在尝试运行查询以使用union all从两个表中提取数据并继续获得以下内容:

  

Msg 245,Level 16,State 1,Line 29
  将nvarchar值'ie9'转换为数据类型int时,转换失败。

我不确定为什么要尝试转换它应该能够显示其表数据?

这是我的SQL:

SELECT 
    CustomerNumber, Event
FROM 
    CustomerPortal.dbo.WebLog
WHERE 
    (Event = 'exception') 
    AND (CreateDate >= '04/03/2015') AND (CreateDate <= '04/06/2015')

UNION ALL

SELECT distinct 
    BrowserId, BrowserName 
FROM 
    CustomerPortal.dbo.BrowserInfoLog;

1 个答案:

答案 0 :(得分:0)

您可以将CustomerNumber转换为nvarchar,以便它与您的BrowserID匹配:

SELECT  CAST(CustomerNumber AS NVARCHAR(128)) AS CustomerNumber ,
        Event
FROM    CustomerPortal.dbo.WebLog
WHERE   ( Event = 'exception' )
        AND ( CreateDate >= '04/03/2015' )
        AND ( CreateDate <= '04/06/2015' )
UNION ALL
SELECT DISTINCT
        BrowserId ,
        BrowserName
FROM    CustomerPortal.dbo.BrowserInfoLog;