Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

conditions in stored procedure

Status
Not open for further replies.

magmo

Programmer
May 26, 2004
291
SE
Hi


Is it possible to check if a value in a stored procedure is "" and if so not make an update.

Code:
    UPDATE
        tbl_database
    SET
      txt1 = @txt1,
      txt2 = @txt2,
    WHERE
       (ID = @ID)


Lets say for example that @txt1 is "" then I don't want to make any update for txt1. Is this possible?



Regards
 
if @txt1 <> ''
begin
UPDATE
tbl_database
SET
txt1 = @txt1,
txt2 = @txt2
WHERE
(ID = @ID)
end
else
begin
UPDATE
tbl_database
SET
txt2 = @txt2
WHERE
(ID = @ID)

end

Or you would have to use dynamic SQL

“I sense many useless updates in you... Useless updates lead to defragmentation... Defragmentation leads to downtime...Downtime leads to suffering..Defragmentation is the path to the darkside.. DBCC INDEXDEFRAG and DBCC DBREINDEX are the force...May the force be with you" --
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top