我们如何在sql server中拆分或分隔列的字符串和整数值? [英] How can we Split or Separate string and integer value of a column in sql server?

查看:80
本文介绍了我们如何在sql server中拆分或分隔列的字符串和整数值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,



如何在sql server中拆分或分隔列的字符串和整数值?



我的栏目价值: -

产品名称
定制的Kreation衣柜1
定制的Kreation衣柜2
定制的Kreation衣柜3
定制的Kreation衣柜4
定制的Kreation衣柜n



我想从这个值中分割整数并为整数创建临时列。



喜欢: -

 ProductName Id 
自定义Kreation衣柜1
定制Kreation衣柜2
定制Kreation衣柜3
定制Kreation衣柜4
定制Kreation衣柜n



如何它可以吗?



在此先感谢。

Ankit Agarwal

软件工程师

解决方案

检查链接

http://stackoverflow.com/questions/9629880/extract-numbers -from-a-text-in-sql-server [ ^ ]

快乐编码!

:)


试试这个:

  SELECT  
LEFT ([产品名称],LEN([产品名称]) - CHARINDEX(' ', REVERSE([产品名称]))) AS productname,
RIGHT ([产品名称] ,CHARINDEX(' ',REVERSE([product name])) - 1 AS id FROM table1



这适用于任何长度的字符串和数字。


这只是您或某人滥用数据库的结果。如果第一个位置,该列应为数字。数据的文本部分应该在一个单独的列中,或者可能根本不需要。



-SA

Hello,

How can we Split or Separate string and integer value of a column in sql server?

My column Value:-

Product Name
"Customized Kreation Wardrobe 1"
"Customized Kreation Wardrobe 2"
"Customized Kreation Wardrobe 3"
"Customized Kreation Wardrobe 4"
"Customized Kreation Wardrobe n"


I want to split integer from this value and create temporary column for integer.

Like:-

ProductName                        Id
Customized Kreation Wardrobe       1
Customized Kreation Wardrobe       2
Customized Kreation Wardrobe       3
Customized Kreation Wardrobe       4
Customized Kreation Wardrobe       n


How it can be possible?

Thanks in Advance.
Ankit Agarwal
Software Engineer

解决方案

check link
http://stackoverflow.com/questions/9629880/extract-numbers-from-a-text-in-sql-server[^]
Happy Coding!
:)


Try this:

SELECT
LEFT([product name], LEN([product name]) - CHARINDEX(' ', REVERSE([product name]))) AS productname,
RIGHT([product name], CHARINDEX(' ', REVERSE([product name])) - 1) AS id FROM table1


This will work for any length of string and number.


This is merely the consequence of the fact that you or someone abused the database. The column should be numeric if first place. The text part of your data should be in a separate column, or maybe it is not needed at all.

—SA


这篇关于我们如何在sql server中拆分或分隔列的字符串和整数值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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