参数数据类型VARCHAR对于基因函数的参数2无效

发布于 2025-02-12 02:02:50 字数 341 浏览 0 评论 0原文

我正在尝试将2x'-'在电话号码中放置,并且我会收到以下错误

参数数据类型VARCHAR对于基因的参数2无效 功能。

我正在研究TSQL。我也尝试“中间”功能 - 没有结果。我需要像“ 123-456-789”这样的结果。

declare @tel nvarchar(20) = 123456789
set @tel = (select left (@tel, '3'))+'-'+(select substring (@tel, '4','3'))+'-'+(select right (@tel, '3'))
select @tel

I'm trying to put 2x'-' in phone number and I'm getting the following error

Argument data type varchar is invalid for argument 2 of substring
function.

I'm working on Tsql. I also try 'mid' function - no results. I need a result like '123-456-789'.

declare @tel nvarchar(20) = 123456789
set @tel = (select left (@tel, '3'))+'-'+(select substring (@tel, '4','3'))+'-'+(select right (@tel, '3'))
select @tel

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

倥絔 2025-02-19 02:02:50

您的查询修改如下所示,

declare @tel nvarchar(20) = '123456789'
set @tel = (select left (@tel, 3))+'-'+(select substring (@tel, 4,3))+'-'+(select right (@tel, 3))
select @tel

可以按照以下来写

declare @tel nvarchar(20) = '123456789'
set @tel = left (@tel, 3)+'-'+substring (@tel, 4,3)+'-'+ right (@tel, 3)
select @tel

Your Query modified as below

declare @tel nvarchar(20) = '123456789'
set @tel = (select left (@tel, 3))+'-'+(select substring (@tel, 4,3))+'-'+(select right (@tel, 3))
select @tel

can Re write as below

declare @tel nvarchar(20) = '123456789'
set @tel = left (@tel, 3)+'-'+substring (@tel, 4,3)+'-'+ right (@tel, 3)
select @tel
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文