Have you tried like this before?

CREATE VIEW [dbo].[ViewName]
AS


Select
Case When Len(Isnull(employee_id,''))=12 then
Case when Isnumeric(Left(Isnull(employee_id,''),4))=1
then
Left(Isnull(employee_id,''),4)
else
''
end
else
''
end as auto_ssn4,
Case When Len(Isnull(employee_id,''))=12 then
Case when ISDATE
(Left(Right(Isnull(employee_id,''),8),2)+'/'+
Left(Right(Isnull(employee_id,''),6),2)+'/'+
Right(Right(Isnull(employee_id,''),8),4))=1 then
Left(Right(Isnull(employee_id,''),8),2)
+
Left(Right(Isnull(employee_id,''),6),2)
+
Right(Right(Isnull(employee_id,''),8),4)
else
''
end
else
''
end as auto_dob
from tablename





GO

--View often for More Updates

No comments:

Post a Comment