Author |
Topic |
kwikwisi
Constraint Violating Yak Guru
283 Posts |
Posted - 2008-08-04 : 06:33:41
|
With this procudure, cannot update if existing cmt is "NULL",May i know what's wrong?CREATE PROCEDURE [dbo].[upt] @id int,@cmt nvarchar(500),@dc datetimeASupdate tblRenewalListset cmt=cmt + @cmt,DateClosed=@dcwhere AutoID=@idGO |
|
elancaster
A very urgent SQL Yakette
1208 Posts |
Posted - 2008-08-04 : 06:38:17
|
adding anything to a null means the whole string will become null. look at coalesce or isnull in books onlineEm |
 |
|
kwikwisi
Constraint Violating Yak Guru
283 Posts |
Posted - 2008-08-04 : 06:42:51
|
Plz can u suggest me how can i modify it?quote: Originally posted by elancaster adding anything to a null means the whole string will become null. look at coalesce or isnull in books onlineEm
|
 |
|
elancaster
A very urgent SQL Yakette
1208 Posts |
Posted - 2008-08-04 : 06:44:34
|
did you look up coalesce and try and figure it out?Em |
 |
|
kwikwisi
Constraint Violating Yak Guru
283 Posts |
Posted - 2008-08-04 : 06:48:44
|
I tried,but i'm confusing..quote: Originally posted by elancaster did you look up coalesce and try and figure it out?Em
|
 |
|
elancaster
A very urgent SQL Yakette
1208 Posts |
Posted - 2008-08-04 : 06:51:46
|
show us what you tried thenEm |
 |
|
kwikwisi
Constraint Violating Yak Guru
283 Posts |
Posted - 2008-08-04 : 06:57:08
|
Actually, I'm new in sqlI'm afraid to show my statement coz incorrect syntaxBut i'll show u CREATE PROCEDURE [dbo].[d_Update] @id int,@cmt nvarchar(500),@dc datetimeASupdate Tableif not isnull(Cmt) thenset Cmt=Cmt + @cmt,DateClosed=@dcelseset Cmt=@cmt,DateClosed=@dcend ifwhere AutoID=@idGOquote: Originally posted by elancaster show us what you tried thenEm
|
 |
|
elancaster
A very urgent SQL Yakette
1208 Posts |
Posted - 2008-08-04 : 07:00:01
|
from BOL...quote: SyntaxISNULL ( check_expression , replacement_value )Argumentscheck_expression Is the expression to be checked for NULL. check_expression can be of any type.replacement_value Is the expression to be returned if check_expression is NULL. replacement_value must be of a type that is implicitly convertible to the type of check_expresssion.
...so in your case the check_expression could just be cmt ? and the replacement_value could just be an empty string?so...update tblRenewalListset cmt = isnull(cmt,'') + @cmt,DateClosed=@dcwhere AutoID=@idEm |
 |
|
kwikwisi
Constraint Violating Yak Guru
283 Posts |
Posted - 2008-08-04 : 07:08:43
|
Thank u  quote: Originally posted by elancaster from BOL...quote: SyntaxISNULL ( check_expression , replacement_value )Argumentscheck_expression Is the expression to be checked for NULL. check_expression can be of any type.replacement_value Is the expression to be returned if check_expression is NULL. replacement_value must be of a type that is implicitly convertible to the type of check_expresssion.
...so in your case the check_expression could just be cmt ? and the replacement_value could just be an empty string?so...update tblRenewalListset cmt = isnull(cmt,'') + @cmt,DateClosed=@dcwhere AutoID=@idEm
|
 |
|
|