-1

I have a table where as codes are present in the form of 78,7244,d345 by default few records are found where the codes are start with 0072 .

I have to delete starting two number (00) from all codes wherever its present in column.

Thom A
  • 88,727
  • 11
  • 45
  • 75
  • Sample data, expected results, *and* your attempts and details of why they didn't work will help us help you. – Thom A May 04 '22 at 12:07
  • Better question is why you store a series of values (numbers?) in a CSV string. This would be trivial (or even non-existent) if the table were properly normalized. – SMor May 04 '22 at 12:54
  • Please provide enough code so others can better understand or reproduce the problem. – Community May 04 '22 at 16:35
  • @SMor The reason why someone asks a question like this is because they've gotten data from an outside source they have no control over and they want to fix it. – Jeff Moden May 05 '22 at 04:37
  • @pinkysharma - Are you saying that your example of 78,7244,d345 is 3 codes stored as a CSV in a single column? Are you also saying that any of those 3 codes could have a leading "00"? And are you saying that you want to leave it as a CSV after deleting the offending leading "00" from any of the 3 codes? – Jeff Moden May 05 '22 at 04:42
  • Does this answer your question? [Better techniques for trimming leading zeros in SQL Server?](https://stackoverflow.com/questions/662383/better-techniques-for-trimming-leading-zeros-in-sql-server) – James Casey May 06 '22 at 08:02

1 Answers1

1

You could test for it like:

select 
    case 
        when code like '00%' 
        then right(code,len(code)-2) 
        else code end AS Code
from YourTable
C J
  • 144
  • 8