用字符串连接数字 [英] Concatenate Number with string
本文介绍了用字符串连接数字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要生成1283-3545-6482之类的数字
即附加'' - ''的4位数字3次,我正在使用此功能生成4位数nnumber
Hi,
I need to generate number like 1283-3545-6482
i.e. 4digit number appended with ''-'' 3 times and i am using this function to generate 4 digit nnumber
select round(cast(((9999 - 1000) * Rand() + 1000)as varchar),0)
当我用'' - ''附加这个值时,它会给出错误
And when i appended this value with ''-'' it gives error
select round(cast(((9999 - 1000) * Rand() + 1000)as varchar),0)+cast('-' as varchar)
错误:
Msg 8114,Level 16,State 5,Line 1
将数据类型varchar转换为浮动时出错。
请给我建议解决此问题
提前致谢
Shilpi
ERROR:
Msg 8114, Level 16, State 5, Line 1
Error converting data type varchar to float.
Please give me suggestion to resolve this problem
Thanks in advance
Shilpi
推荐答案
试试以下:
Try the following :
select cast( round( (9999-1000)*Rand()+1000, 0) as varchar) + '-'
这篇关于用字符串连接数字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文