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.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 invalid values

Author  Topic 

sqlfresher2k7
Aged Yak Warrior

623 Posts

Posted - 2012-08-28 : 15:21:06
I need a query to identify and ignore the below characters value to insert.

Ex: 32.

+40


tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2012-08-28 : 15:55:43
I don't understand what you want.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

sqlfresher2k7
Aged Yak Warrior

623 Posts

Posted - 2012-08-28 : 16:07:46
I do not want to insert the records which has invalid characters with + and or . (Plus and or .)in a value.

Ex:

col1 varchar (50)

Source table

col1
----
44.
33
22.
10+
.14
+15
1+1
1.5

Expected results:

Destination table

Col1
----
33

Please let me know if i m not clear.

Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2012-08-28 : 16:19:49
You can use ISNUMERIC function for this.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

russell
Pyro-ma-ni-yak

5072 Posts

Posted - 2012-08-29 : 08:46:44
ISNUMERIC won't return expected results. For example 1.5 will be returned.

This should do it:
WHERE col1 NOT LIKE '%[^0-9]%'
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2012-08-29 : 12:13:59
Oh I missed 1.5 in the example. Good catch.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page
   

- Advertisement -