更改视图列的数据类型时出错

时间:2013-07-17 09:26:35

标签: sql sql-server database

create view [dbo].[view_name] as SELECT cast(Table1.col1 as bigint), Table1.col2, Table2.col3, cast(Table2.col4  as double)
FROM Table1 INNER JOIN
Table2 ON Table1.col1  = Table2.col1 

显示错误“错误'''”

上述查询中的错误是什么。我使用的是sql server 2008。

修改

create view [dbo].[SP_AHU_data] as SELECT cast(TrendLog.TrendLogId as bigint) as TrendLogid , TrendLog.TrendLogGuid, TrendLogValue.LogTime,cast(TrendLogValue.LogValue as double) as LogValue 
FROM TrendLog INNER JOIN
TrendLogValue ON TrendLog.TrendLogId = TrendLogValue.TrendLogId
where TrendLog.TrendLogGuid in('{DCCFB6EA-C606-4168-A2B3-FC1059173DAF}',
'{B1D5B0E8-44E2-459B-BC53-1CCE00FE7E6E}',
'{7493BB54-DC88-4ECF-81DA-3AEBCC698808}',
'{9641A376-D03D-46B7-9780-20DAC28AA3D9}')

有两个表TrendLog和TrendLogValue

Trendlog有2列

  1. TrendLogId(PK,smallint notnull)
  2. trendlogguid(uniqueidentifier not null)
  3. trendLogValue有3列

    1. TrendLogId(PK,smallint notnull)
    2. LogValue(float notnull)
    3. LogTime(datetime notnull)

1 个答案:

答案 0 :(得分:2)

尝试按以下方式添加别名,并将double更改为float

create view [dbo].[view_name] as 
SELECT cast(Table1.col1 as bigint) as col1, 
       Table1.col2, Table2.col3, 
       cast(Table2.col4  as float) as col4
FROM Table1 INNER JOIN
Table2 ON Table1.col1  = Table2.col1 

Sql fiddle demo

Double类型不是sql server的类型:MSDN