I am working on a table in sql to add a new column using existing column of phone number and filter our the valid and invalid phone numbers n the new column.
Here are the conditions-
1. Phone number should 10 digit and should start with 8 or 9.
2. Phone number should 11 digit and its first two digits should be 0 and 9.
3. Phone number should 12 digit and its first two digits should be 9 and 1.
4. Phone number should not start with any alphabet.
5. If the phone number abides by any one of the above given conditions then it should show up in the new column else it should show up as invalid or Null.
Here is something that i have tried but not working:
Select *, ROW_NUMBER() over (partition by [Phone No] order by [Customer No] DESC) as RowNumber,
(Select(ltrim(rtrim([Phone No])) like '[^a-z]%' and
((len(ltrim(rtrim([Phone No]))) = 10 and [Phone No] like '[89]%') or ([Phone No] like
case when (len(ltrim(rtrim([Phone No]))) = 11 and [Phone No] like '[0][9]%') then
[Phone No]
end) or (len(ltrim(rtrim([Phone No]))) = 12 and [Phone No] like '[9][1]%'))) from
[Data_Joined])
from [Data_Joined]
Please help! Thanks.