Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
paramu
Posting Yak Master
151 Posts |
Posted - 2012-10-15 : 08:40:22
|
HiIam using SQL Server 2008. I wish to select only numeric values in a item_code field. Is it possible? Item_Table==========item_code, item_name, item_description from Item_Tableitm0, Pencil, Stationeriesitm1, Pen, Stationeriesitm2, Eraser, Stationeriesitm3, Table, Assetsitm4, Chair, Assetsand so...on...My Query========select (item_code)????? as my_code_number, item_name, item_description from Item_TableThanksParamu @ PARANTHAMAN |
|
sunitabeck
Master Smack Fu Yak Hacker
5155 Posts |
Posted - 2012-10-15 : 08:44:10
|
Do you mean that a) you want to select only those rows in which item_code is a number - e.g., you have 1234 and abc24 in two rows, and you want to get only one row out of those two - the one that has 1234orb) your item_code is a combination of digits and other characters, and you want to pick out the numbers out of those? e.g., you have 1234 and abc24 in two rows and you want to get two rows with item_codes as 1234 and 24? |
|
|
paramu
Posting Yak Master
151 Posts |
Posted - 2012-10-15 : 08:56:16
|
Hi sunita, thanks, after long gap, again I get you today... I wish to get the result like the below0, Pencil, Stationeries1, Pen, Stationeries2, Eraser, Stationeries3, Table, Assets4, Chair, AssetsI wish to select only the numbers in item_code as new field...ThanksParamu @ PARANTHAMAN |
|
|
lionofdezert
Aged Yak Warrior
885 Posts |
Posted - 2012-10-15 : 08:58:54
|
for such removals i like to use following functionsalter FUNCTION dbo.RemoveSpecialChars ( @InputString VARCHAR(8000) )RETURNS VARCHAR(8000)BEGIN IF @InputString IS NULL RETURN NULL DECLARE @OutputString VARCHAR(8000) SET @OutputString = '' DECLARE @l INT SET @l = LEN(@InputString) DECLARE @p INT SET @p = 1 WHILE @p <= @l BEGIN DECLARE @c INT SET @c = ASCII(SUBSTRING(@InputString, @p, 1)) IF @c BETWEEN 48 AND 57 --OR @c BETWEEN 65 AND 90 --also remove A to Z --OR @c BETWEEN 97 AND 122 --also remove a to z --OR @c = 32 SET @OutputString = @OutputString + CHAR(@c) SET @p = @p + 1 END IF LEN(@OutputString) = 0 RETURN NULL RETURN @OutputStringEND--------------------------http://connectsql.blogspot.com/ |
|
|
lionofdezert
Aged Yak Warrior
885 Posts |
Posted - 2012-10-15 : 08:59:13
|
http://connectsql.blogspot.com/2011/05/sql-server-how-to-remove-special.html--------------------------http://connectsql.blogspot.com/ |
|
|
paramu
Posting Yak Master
151 Posts |
Posted - 2012-10-15 : 09:19:09
|
Thanks...Paramu @ PARANTHAMAN |
|
|
|
|
|
|
|