Basically, I am looking to modify a stored procedure that I have in my database already that updates a table's records (table x) with data coming from a web application. After updating table x, I want to develop that stored procedure to check table x to see if there exist anymore records for that instance of the primary key where column_z is null. Basically, something like
ALTER PROCEDURE [cred].[UpdateTablex]
(@field0 int,
@field1 int,
@field2 int,
@field3, int,
@field4 VARCHAR(100),
@field5 datetime,
@field6 datetime)
AS
UPDATE tablex
SET field4 = @field4,
field6 = @field6
WHERE field1 = @field1 AND
field2 = @field2 AND
field3 = @field3 AND
field0 = @field0 AND
field5 = @field5;
The rest of this will be psuedocode for my idea and the way I thought it might be developed
IF ((SELECT COUNT(field0) FROM tablex WHERE field6 is null AND field2 = @field2
AND field3 = @field3 AND field5 = @field5) equals 0)
exec cred.Demobilize(@field0, @field1);
Or simply, if that Select statement returns any results indicating that field6 is null anywhere then we do nothing. Obviously that would mean then that if the Select statement returns nothing, then I want to execute another stored procedure.
This is probably something simple so please forgive me as I'm kinda new to certain types of SQL syntax and usage, this being one of them.
Also, could anybody point me in a proper direction to further educate myself on topics like this?
Thank you.
DECLARE @counter int SET @counter = SELECT.... Yes?COUNTis NOT best practice. Please useEXISTSinstead. You don't need the darn count just to tell if there are any at all.