SQL Server
A family of Microsoft relational database management and analysis systems for e-commerce, line-of-business, and data warehousing solutions.
14,282 questions
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
I work on sql server 2017 i need to validate user input of temp table
if formate of created date not YYYY-MM-DD then reject by update status field of temp table to be Notvalid
and if formate of created date is YYYY-MM-DD then update status by Valid
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
CREATE TABLE #TempPC
(
[ID] INT IDENTITY ,
CreatedDate varchar(12),
status varchar(200)
)
insert into #TempPC ( CreatedDate )
select '2022-05-09'
union all
select '12-15-2022'
union all
select '13-04-2022'
Select CreatedDate
,Case when try_Convert(date,CreatedDate,120) is null then 'NotValid' else 'Valid' end Status
from #TempPC
drop TABLE #TempPC