Skip to main content
added 2 characters in body
Source Link
Ben
  • 53.1k
  • 36
  • 133
  • 156

If you want the query to return a 0 instead of a string of zeroes or any other value for that matter you can turn this into a case statement like this:

select CASE WHEN ColumnName = substring(ColumnName, patindex('%[^0]%',ColumnName), 10) THEN '0' ELSE substring(ColumnName, patindex('%[^0]%',ColumnName), 10) END

select CASE WHEN ColumnName = substring(ColumnName, patindex('%[^0]%',ColumnName), 10) THEN '0' ELSE substring(ColumnName, patindex('%[^0]%',ColumnName), 10) END 

If you want the query to return a 0 instead of a string of zeroes or any other value for that matter you can turn this into a case statement like this:

select CASE WHEN ColumnName = substring(ColumnName, patindex('%[^0]%',ColumnName), 10) THEN '0' ELSE substring(ColumnName, patindex('%[^0]%',ColumnName), 10) END

If you want the query to return a 0 instead of a string of zeroes or any other value for that matter you can turn this into a case statement like this:

select CASE WHEN ColumnName = substring(ColumnName, patindex('%[^0]%',ColumnName), 10) THEN '0' ELSE substring(ColumnName, patindex('%[^0]%',ColumnName), 10) END 
Source Link

If you want the query to return a 0 instead of a string of zeroes or any other value for that matter you can turn this into a case statement like this:

select CASE WHEN ColumnName = substring(ColumnName, patindex('%[^0]%',ColumnName), 10) THEN '0' ELSE substring(ColumnName, patindex('%[^0]%',ColumnName), 10) END