Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 How to create a procedure to do all updates?

Author  Topic 

sqlontherun101
Starting Member

16 Posts

Posted - 2009-08-27 : 06:46:53
Hi,

I have modified my previoseu thread to this new thread:

I need to create a procedure with one update statement that is capable of updating a table of three columns. where one column (CustNo) is auto increment.

The table has three columns
1. CustNo
2. CustCatName
3. CustCatDescription

Therefreo from the business layer, thsi table can be updated in following ways:

1. update ONLY CustCatName column
2. udpate ONLY custCatDescription column
3. update both custCatName and CustCatDescription

Therefore in common sense i have to create three update statenents in a Storeproceudre. But i need to create one update statement by check updates to other columns are avalable. If updates avlabel the inout paramter should have a value else NULL.

I have written the followin sketch but i need some assitance in completing my procedure. OR if you have another way of doing this please let me know.

ALTER PROCEDURE ProcUpdateCustomerCategories


@PCustCatName AS NVARCHAR(100),
@PCustCatDescr as NVARCHAR(MAX),
@PCustCatNo AS INT

AS
BEGIN



IF @PCustCatName IS NOT NULL

--ADD THE PCustCatName to the update statement

ELSE
IF @PCustCatDescr IS NOT NULL

-- Add the PCustCatAddress to the update statement



update tblCustomerCategories
SET <something here>

where catNo = @PCustCatNo;

END
GO

TY in advance

vijayisonly
Master Smack Fu Yak Hacker

1836 Posts

Posted - 2009-08-27 : 08:42:15
Try this..

update tblCustomerCategories 
SET CustCatName = COALESCE(@PCustCatName,CustCatName),
CustCatDescription = COALESCE(@PCustCatDescr,CustCatDescription)
where catNo = @PCustCatNo

Go to Top of Page
   

- Advertisement -