Stored Procedure to check parameters contain value or not.

Posted by Sathiya_Narayanan under Sql Server on 10/3/2012 | Points: 10 | Views : 2252 | Status : [Member] | Replies : 3
Hi,

How to create the stored procedure for update & delete if any of the column value is empty in database its not updating the row.

eg: name, age, place, date.
there are 4 columns 3columns has value and 1column does not have value in db.
but when passing parameters.
it should check if all the parameters values are passed are not if not it should set the value as null for which parameter is empty.

SATHIYANARAYANAN


Responses

Posted by: Rickeybglr on: 10/3/2012 [Member] Starter | Points: 25

Up
0
Down
use
ISNULL(col_name,NULL)

Sathiya_Narayanan, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Divyaselvarathinam on: 10/3/2012 [Member] Starter | Points: 25

Up
0
Down
Use ISNULL(columnname,'NULL') to insert null into table

Assuming that empty value is passed for the column place,

Your stored procedure might look like tiz

CREATE procedure [STUD].[updnull]
(@name as varchar(50),
@age as int,
@place as varchar(50),
@date as date
)
as
Begin
Update Updatenull set Age=@age,Place=IsNull(@place,'Null'),Date=@date where Name=@name
end

Divya

Sathiya_Narayanan, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Niladri.Biswas on: 10/4/2012 [Member] Platinum | Points: 25

Up
0
Down
You can use ISNULL , COALESCE or a CASE statement for this purpose

Best Regards,
Niladri Biswas

Sathiya_Narayanan, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response