0

I would typically load data via bulk insert from a text file into a database. All as nvarchar. I have it all setup as stored procedures which means very fast turn around with minimal rewriting of the scripts. Occasionally however the amount column can cause as issue. For example some extracts we receive contain "-" for 0, others will show negative figure as (10.00). This means when I try to cast amount column as a float I get an error.

What is the best way to catch and identify these random characters in an automated fashion?

Calgar99
  • 1,670
  • 5
  • 26
  • 42

1 Answers1

2

Well, for identifying I think you can use a regular expression in the form of something like this:

SELECT AmountColumn
FROM yourTable
WHERE PATINDEX('%[^.0-9]%', AmountColumn) > 0

This will catch all of the amounts which have any other characters than numbers, including special characters, letters etc. after they have been inserted in the table.

If you want these values to be treated during the runtime of the stored procedure, I think it would be best to add the code of the SP and some more details.

Radu Gheorghiu
  • 20,049
  • 16
  • 72
  • 107
  • Hi Radu, I tried applying your solution, however if an entry is 1.2 then it appears in the list. I then amended it to '%[^0-9].% however it captures $1$.3 but not $1.3 – Calgar99 Oct 14 '14 at 14:33
  • @Calgar99 My solution will show you all the amounts that have **anything except numbers**, inlcuding dots. I will update my answer to something that will work correctly with `1.3` – Radu Gheorghiu Oct 14 '14 at 14:41
  • @Calgar99 Please try now. All that you had to do is move the dot from outside of the square paranthesis to the inside, before the 0. Please see updated answer. – Radu Gheorghiu Oct 14 '14 at 14:43