A Microsoft extension to the ANSI SQL language that includes procedural programming, local variables, and various support functions.
Hi @John K ,
I think what you want can be achieved through dynamic sql. Since you can't provide DDL and expected output, I did some tests based on my understanding, I hope it will be useful to you.In addition, the PKcol='null' field is more convenient to update with ordinary SQL:
create table test
( PKcol char(25),
Datatype char(25),
faultyrowflag char(25))
insert into test values('StudentID','int',''),
('Nationality', 'varchar',''),
('DOB','Date',''),
('Collegeid','Int',''),('null','Int','')
update test
set faultyrowflag ='null primary key'
from test
where PKcol='null'
create procedure b_stu
(@pkcol varchar(25),@datatype varchar(25))
as
if @datatype<>(select Datatype from test where pkcol=@pkcol)
update test
set faultyrowflag ='invalid date'
from test
where pkcol=@pkcol
exec b_stu @pkcol=StudentID, @datatype=date
select * from test
drop table test
drop procedure b_stu
Best Regards
Echo
If you have any question, please feel free to let me know.
If the response is helpful, please click "Accept Answer" and upvote it.
If the answer is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.
