Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

question about update record Expand / Collapse
Author
Message
Posted Sunday, March 6, 2011 12:24 PM
SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Tuesday, July 16, 2013 6:46 AM
Points: 33, Visits: 94
hi.i have a table that contains id,header,content,image fileds. id is primary key. Other fields are string fields(varchar). i keep image's path on the image field. update stored proc of my is like this:

create procedure Upd_Info
@hea varchar(max)=null,
@cont varchar(max)=null,
@im varchar(max)=null
as
begin
update Info set header=@hea,content=@cont,image=@im
end

if i don't give value a field on update proc running,it gives null value that field.(this is normal for this proc)

what i want to do is this: if i don't give value to the filed, that fied will be protect old value. Or else it takes new value.
for example, a row has value of (aa,qqq,img/p.jpg)
if i runs update proc parameters like (ww,cc) values, i want image filed doesn't change. row wil be remain with ww,cc,img/p.jpg values.

i hope, i can express my problem properly. Thanks.
Post #1073890
Posted Sunday, March 6, 2011 12:56 PM


SSC-Dedicated

SSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-Dedicated

Group: General Forum Members
Last Login: Today @ 1:57 PM
Points: 35,372, Visits: 31,919
update Info set header=ISNULL(@hea,header),content=ISNULL(@cont,content),image=(@im,image)




--Jeff Moden
"RBAR is pronounced "ree-bar" and is a "Modenism" for "Row-By-Agonizing-Row".

First step towards the paradigm shift of writing Set Based code:
Stop thinking about what you want to do to a row... think, instead, of what you want to do to a column."

(play on words) "Just because you CAN do something in T-SQL, doesn't mean you SHOULDN'T." --22 Aug 2013

Helpful Links:
How to post code problems
How to post performance problems
Post #1073895
Posted Sunday, March 6, 2011 5:01 PM


Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Monday, September 29, 2014 7:25 AM
Points: 1,221, Visits: 1,294
don't forget the where clause or all of your records will be the same

For better, quicker answers, click on the following...
http://www.sqlservercentral.com/articles/Best+Practices/61537/

For better answers on performance questions, click on the following...
http://www.sqlservercentral.com/articles/SQLServerCentral/66909/
Post #1073912
Posted Monday, March 7, 2011 6:16 AM


SSC-Dedicated

SSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-Dedicated

Group: General Forum Members
Last Login: Today @ 1:57 PM
Points: 35,372, Visits: 31,919
Mike01 (3/6/2011)
don't forget the where clause or all of your records will be the same


Thanks for the catch, Mike. Shamefully, I only fixed what I saw.


--Jeff Moden
"RBAR is pronounced "ree-bar" and is a "Modenism" for "Row-By-Agonizing-Row".

First step towards the paradigm shift of writing Set Based code:
Stop thinking about what you want to do to a row... think, instead, of what you want to do to a column."

(play on words) "Just because you CAN do something in T-SQL, doesn't mean you SHOULDN'T." --22 Aug 2013

Helpful Links:
How to post code problems
How to post performance problems
Post #1074096
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse