MS SQL Server视图不允许CONCAT [英] MS SQL Server View not allowing CONCAT

查看:311
本文介绍了MS SQL Server视图不允许CONCAT的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

MS SQL Server 2014。



我有一条运行良好的SQL语句:

  SELECT CONCAT(
CAST(T1。[F1] AS INTEGER),
CAST(T1。[F2] AS INTEGER)
)AS F3
FROM mytable AS T1

如果我将其放入视图并尝试运行,则会收到错误消息:

 操作数数据类型int对concat运算符


F1和F2都包含小数,但我希望它们连接起来,例如:

  F1 = 123.00000 
F2 = 456.00000

因此 F3 = 123456



为什么视图不允许这样做并且有解决方案?

解决方案

不要使用视觉设计器。



它们是越野车,在这种情况下转换

 选择联系人(
CAST(T1。[F1] AS INTEGER),
CAST(T1。[F2] AS INTEGER)
)AS F3
from mytable AS T1

  SELECT {fn CONCAT(CAST (T1.F1 AS INTEGER),CAST(T1.F2 AS INTEGER))} AS F3 
来自mytable AS T1

调用高度受限的函数的ODBC转义序列版本(仅接受两个必须为字符串的参数)



只需使用标准的新查询窗口以执行您的创建视图 / 更改视图 / 选择自操作,您将不会得到这个问题ue。


MS SQL Server 2014.

I have a SQL statement that works fine:

SELECT CONCAT (
        CAST(T1.[F1] AS INTEGER),
        CAST(T1.[F2] AS INTEGER)
        ) AS F3 
FROM mytable AS T1

If I then put this into a view, and try to run I receive the error:

Operand data type int is invalid for concat operator

F1 and F2 both contain decimals but I want them concatenating e.g.:

F1 = 123.00000
F2 = 456.00000

Therefore F3 = 123456

Why does the view not allow this and is there a solution?

解决方案

Don't use the visual designers.

They are buggy and in this case convert

    SELECT CONCAT (
        CAST(T1.[F1] AS INTEGER),
        CAST(T1.[F2] AS INTEGER)
        ) AS F3 
FROM mytable AS T1

to

SELECT { fn CONCAT(CAST(T1.F1 AS INTEGER), CAST(T1.F2 AS INTEGER)) } AS F3
FROM     mytable AS T1

Calling the highly limited ODBC escape sequence version of the function (that only accepts two parameters which must be strings)

Just use a standard new query window to execute your CREATE VIEW/ALTER VIEW/SELECT FROM operations and you won't get this issue.

这篇关于MS SQL Server视图不允许CONCAT的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆