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
它显示错误“error on ')'”
上面的查询有什么错误。我使用的是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
趋势日志有 2 列
- TrendLogId (PK,smallint notnull)
- trendlogguid(uniqueidentifier not null)
trendLogValue 有 3 列
- TrendLogId (PK,smallint notnull)
- LogValue(float notnull)
- LogTime(datetime notnull)
最佳答案
尝试如下添加别名并将 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
关于sql - 更改 View 列的数据类型时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17696028/