all groups > sql server programming > november 2004 >
You're in the

sql server programming

group:

Update statement question



Re: Update statement question Dan Guzman
11/8/2004 8:11:29 AM
sql server programming: Try:

UPDATE User
SET name = @name,
pwd = COALESCE(@pwd, pwd)
WHERE id=@id

--
Hope this helps.

Dan Guzman
SQL Server MVP

[quoted text, click to view]

Re: Update statement question Roji. P. Thomas
11/8/2004 7:45:27 PM
update User
set name = @name ,
pwd = Case when @pwd IS NULL Then pwd ELSE @pwd END
where id=@id


--
Roji. P. Thomas
Net Asset Management
https://www.netassetmanagement.com


[quoted text, click to view]

Update statement question L.Peter
11/8/2004 10:07:53 PM
Dear Group,
I have this sp:
create procedure UpdateUser
(
@id char(10),
@name char(10),
@pwd char(10)
)
as update User set name = @name , pwd = @pwd where id=@id
return

I have a row
insert into User values('test','peter','pwd')
Question : How can I NOT update field pwd if the @pwd is null (if it is not
then it should be updated)?
something like:
exec UpdateUser 'test','Rob',null --> the field pwd remains 'pwd'
exec UpdateUser 'test','Rob','newpwd' --> the field pwd is changed to
'newpwd'

TIA

Peter

Re: Update statement question L.Peter
11/8/2004 10:17:33 PM
Well, I am shocked, never get replies so fast.

Thank you guys

Peter
[quoted text, click to view]

AddThis Social Bookmark Button