CREATE TABLE #TempPC ( [ID] INT IDENTITY , CreatedDate varchar(12), status varchar(200) ) insert into #TempPC ( CreatedDate ) select '2022-05-09' union select '12-04-2022'
Expected result CreatedDate Status 2022-05-09 Valid 12-04-2022 NotValid
SELECT Createddate,CASE WHEN ISDATE(CreatedDate) = 1 AND CreatedDate LIKE '[1-2][0-9][0-9][0-9]/[0-1][0-9]/[0-3][0-9]' THEN 1 ELSE 0 END as datestatus into #wrongformate from #TempPC; create index wrongformate_idx on #wrongformate(Createddate)include(datestatus) UPDATE t SET t.[status]=case when datestatus=1 then 'Valid' else 'Not Valid' end FROM #TempPC t inner join #wrongformate w on t.CreatedDate=w.CreatedDate where t.status is null
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)