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.
| Author |
Topic |
|
sha_agrawal
Starting Member
24 Posts |
Posted - 2008-12-27 : 07:59:49
|
| I convey my regards to all experts whomsoever reading my problem.I am using SQL SERVER 2000 and VB6.When I fire QueryUpdate IssueTbl set IssueQty=issueQty+(select IQty from TmpTable where Tmptable.itemid=issuetable.itemid)It gives error "Can not insert NULL value in IssueQty". Offcourse Issueqty field in IssueTbl has been set to not accept not Null value but DEFAULT value 0(Zero) has been given. How to avoiod this error?. Pls. help me |
|
|
bklr
Master Smack Fu Yak Hacker
1693 Posts |
Posted - 2008-12-27 : 08:05:40
|
| use isnull or coalesce condition |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-12-27 : 11:47:39
|
quote: Originally posted by sha_agrawal I convey my regards to all experts whomsoever reading my problem.I am using SQL SERVER 2000 and VB6.When I fire QueryUpdate IssueTbl set IssueQty=issueQty+(select IQty from TmpTable where Tmptable.itemid=issuetable.itemid)It gives error "Can not insert NULL value in IssueQty". Offcourse Issueqty field in IssueTbl has been set to not accept not Null value but DEFAULT value 0(Zero) has been given. How to avoiod this error?. Pls. help me
Defaults will be applied only during insert operations. for updation,. you've either use isnull or coalesce to make it 0 or write a trigger. the former one is obviously the best solution. |
 |
|
|
Jai Krishna
Constraint Violating Yak Guru
333 Posts |
Posted - 2008-12-28 : 23:16:11
|
| Try ThisUpdate IssueTbl set IssueQty=issueQty+(select COALESCE(IQty,0) from TmpTable where Tmptable.itemid=issuetable.itemid)ORUpdate IssueTbl set IssueQty=issueQty+(select ISNULL(IQty,0) from TmpTable where Tmptable.itemid=issuetable.itemid)Jai Krishna |
 |
|
|
ashishashish
Constraint Violating Yak Guru
408 Posts |
Posted - 2008-12-29 : 00:22:29
|
| uSE ISNULL to avoid this,,,,,like ISNULL(value,0) |
 |
|
|
robint84
Starting Member
1 Post |
Posted - 2009-01-13 : 12:56:26
|
| You can try this link to know how to update only NON NULL values in update queries when u are using stored procedure http://rttechno.blogspot.com/2009/01/updating-only-non-null-parameters-in.html |
 |
|
|
|
|
|