In sql server, check that the row contains specific values

@Phoneno varchar
@Phoneno='(123)(4520)'

how to check if @Phoneno has a number in the brackets of the arrows? Example

@Phoneno='()()' 
+3
source share
4 answers

You can remove the brackets using the REPALCE function :

DECLARE @Phoneno varchar(1000) = '(123)(4520)';

SET @Phoneno = REPLACE(REPLACE(@Phoneno, '(', ''), ')', '');

IF (ISNUMERIC(@Phoneno) = 1) 
   SELECT 'Phoneno not empty';
ELSE
   SELECT 'Phoneno empty or invalid';
+1
source

If you want to check if phone numbers are in the format (nnn) (nnnn), where in the first part there should be 3 numbers and in the second part there should be 4 numbers, you can do this:

if @Phoneno like '([0-9][0-9][0-9])([0-9][0-9][0-9][0-9])'
    print 'ok'
else
    print 'not ok'

An insignificant thing with the ISNUMERIC method is the decimal sign and minus sign. This can be eliminated by replacing these characters with a blank one (but still will not check the correct length).

+1
source

, SQL Server.

SQL Server 2005 , CLR - - .

.

0

, , ! "(" ")" , , , ()() null.

-1

Source: https://habr.com/ru/post/1736498/


All Articles