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
 SQL Server 2000 Forums
 Transact-SQL (2000)
 generic update

Author  Topic 

fmardani
Constraint Violating Yak Guru

433 Posts

Posted - 2006-12-13 : 06:42:21
Hi,
Could you please let me know how to modify the below query if say the Description field is entered or not.

For example in the query below the description field value is entered. But what if the Description field is not entered? What will the query look like then?
Currently I have one update query if the description field is entered. And another update query if there is no Description field entered. I would like to have only one update query that takes into account the two scenarios.

Thank you

UPDATE
Types
SET
[Name] = @NewName,
[Description] = @Description,
LastUpdatedDate = GetDate()
WHERE
TypeID = @TypeID

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2006-12-13 : 06:44:25
If either @NewName or @Description is NULL, the column value retain it's previous value
UPDATE	Types
SET [Name] = ISNULL(@NewName, [Name]),
[Description] = ISNULL(@Description, [Description]),
LastUpdatedDate = GETDATE()
WHERE TypeID = @TypeID


Peter Larsson
Helsingborg, Sweden
Go to Top of Page
   

- Advertisement -