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
 Update Statement

Author  Topic 

maya_zakry
Constraint Violating Yak Guru

379 Posts

Posted - 2007-01-05 : 21:38:38
hi all,
how to update a column to the column itself?
i mean i have the scenario that i need to update 10 column at a time but actually 3 will need the real update, the rest i need to reserved the value. My SP will send value s1 til s10 param.. the Q is what value i need to assign to s1 if i want to reserved the old value? maybe something like...

UPDATE tblblabal
SET s1=??,
s2='change2something',
s3='change2something'
til s10

maybe u would ask, why update s1 if u dun wanna update it? it's because i need to prepare for 'needtochange' scenario from my codebehind(vb.net)..



maya_zakry
Constraint Violating Yak Guru

379 Posts

Posted - 2007-01-05 : 21:48:19
this would be no prob without any param..(direct sql)

UPDATE tblblabal
SET s1=s1 <--- setting to its column name will change nothing
s2='change2something',
s3='change2something'

but then if in the stored proc, how do i set the param valum to the column name in my codebehind????

my SP:-

@s1 as varchar(10),
@s2 as varchar(10),
@s3 as varchar(10),

how to set the @s1 to the name of the table column from the codebehind??escape char??




Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2007-01-05 : 23:38:23

Before trying this make sure you have backup of that table

Send NULL value to that S1 provided your Sp is

Create Procedure Test(
@s1 as varchar(10),
@s2 as varchar(10),
@s3 as varchar(10)
) as

UPDATE tblblabal
SET s1=ISNULL(@s1,s1)
s2='change2something',
s3='change2something'

Now Execute SP by

EXEC Test NULL,'somevalue','somevalue'

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

maya_zakry
Constraint Violating Yak Guru

379 Posts

Posted - 2007-01-08 : 02:59:10
hi madhivanan..

this seems to work, but it doesnt.. i dunno what's wrong, it keeps entering null intead of old value
Go to Top of Page

maya_zakry
Constraint Violating Yak Guru

379 Posts

Posted - 2007-01-08 : 03:12:07
finally it works, tq ! but another Q :-
how do we send null value from the codebehind? (vb.net?>
Go to Top of Page

maya_zakry
Constraint Violating Yak Guru

379 Posts

Posted - 2007-01-08 : 03:15:54
System.DBNull.Value
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2007-01-08 : 09:27:36
Glad that you helped yourself

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2007-01-08 : 09:28:52
Glad that you helped yourself

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

maya_zakry
Constraint Violating Yak Guru

379 Posts

Posted - 2007-01-09 : 03:05:39
:P

~~~Focus on problem, not solution~~~
Go to Top of Page
   

- Advertisement -