SQL Server Express:SQL Server Mgmt Studio Express 中的 REPLACE 问题
我在 Microsoft SQL Server Management Studio Express 中的 REPLACE SQL 函数上遇到了一个大问题。
当我执行以下查询时
SELECT REPLACE('ArticleNumber', 'S401', 'I0010')
SELECT REPLACE('ArticleNumber', 'S302', 'I0020')
SELECT REPLACE('ArticleNumber', 'S303', 'I0030')
SELECT REPLACE('ArticleNumber', 'S304', 'I0040')
SELECT REPLACE('ArticleNumber', 'S305', 'I0050')
SELECT REPLACE('ArticleNumber', 'S306', 'I0060')
FROM tbl.Products
,Studio Express Response 与该 SELECT 无法识别。
我做错了什么?
I have a huge problem with the REPLACE SQL function in Microsoft SQL Server Management Studio Express.
When I do following query
SELECT REPLACE('ArticleNumber', 'S401', 'I0010')
SELECT REPLACE('ArticleNumber', 'S302', 'I0020')
SELECT REPLACE('ArticleNumber', 'S303', 'I0030')
SELECT REPLACE('ArticleNumber', 'S304', 'I0040')
SELECT REPLACE('ArticleNumber', 'S305', 'I0050')
SELECT REPLACE('ArticleNumber', 'S306', 'I0060')
FROM tbl.Products
Then Studio Express Response with that SELECT wasn't recognised.
What am I doing wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
根据您想要执行的操作...
您需要嵌套的 REPLACE...
..或多个输出列
注意:错误来自尝试运行此操作的数据库引擎。 SSMS 是一款出色的文本编辑器,具有一些有用的附加功能。
Depending on what you are trying to do...
You need either a nested REPLACE...
..or multiple output columns
Note: the error comes from the database engine that tries to run this. SSMS is a glorified text editor with some useful extras..
文章编号应该用引号引起来吗?
您的替换不会替换任何内容,因为 S401、S302 等绝对不在“ArticleNumber”中。
您需要遵循 gbn 使用嵌套语句的建议,但使用实际的列。
克里斯
Should articlenumber be in quotes?
Your replace is not going to replace anything as S401, S302, etc... are definitely not in 'ArticleNumber.'
You'll want to follow gbn's advice of using a nested statement, but with the actual column.
Kris
也许我只是不明白你想要做什么,但从我在这里可以读到的内容来看,你试图用“I0010”替换字符串“ArticleNumber”中的“S401”,所以选择结果将始终是“ArticleNumber”.... 那么
FROM tbl.Products 是无用的,那么您应该尝试不带引号的 ArticleNumber ,请参阅 GBN 答案以获取确切的语法
如果您想替换表 produtcts 中的 ArticleNumber 字段的值,
maybe i jsut dont get what you are trying to do but from what i can read here you are trying to replace 'S401' in the string 'ArticleNumber' by 'I0010' so the select result will always be 'ArticleNumber' .... and the
FROM tbl.Products is useless
if u want to replace the value of the field ArticleNumber from table produtcts then you should try ArticleNumber with no quote jsut refer to GBN answer for the exact syntax
这是一种略有不同的方法。
This is a slightly different way of doing it.
删除 ArticleNumber 周围的引号并嵌套 REPLACE:
Remove the quotes around ArticleNumber and nest the REPLACEs: