Skip to content
Advertisement

SQL Server query to check if date has the same digit

case statement to validate if date column is all the same number number (ie. 1s, 2s, etc)

DECLARE @opendate varchar 
SET opendate = '11111111' 

SELECT 
    CASE 
        WHEN opendate LIKE '^([0-9a-z])1+$')
            THEN 'invalid' 
    END AS date

Advertisement

Answer

use

declare @opendate varchar(50)
set @opendate = '11111111111' 
select @opendate, case when patindex('%[^'+left(@opendate,1)+']%',@opendate) = 0 then 'valid' else 'invalid' end

demo in db<>fiddle

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement