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 |
|
amalshah71
Starting Member
9 Posts |
Posted - 2006-12-06 : 06:20:59
|
| i have the idea that 23+null=nullnow following is my case with 2 columns as:salary bonus1 null2 53 nulli have to find the total salary(i.e. salary+bonus)this is how i managed to do it:select empname,(salary + commission) as 'total salary'from empwhere commission is not nullunionselect empname,salary from empwhere commission is nullnow my question is,wht if the case now is different as below:salary bonus hra1 null 62 5 null3 null nullnow how do i calculate total salary(i.e. salary+bonus+hra)am a beginnerhelp appreciatedcheers |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2006-12-06 : 06:25:26
|
| select isnull(salary, 0) + isnull(bonus, 0)from yourtablenameherePeter LarssonHelsingborg, Sweden |
 |
|
|
harsh_athalye
Master Smack Fu Yak Hacker
5581 Posts |
Posted - 2006-12-06 : 06:27:22
|
quote: Originally posted by Peso
select isnull(salary, 0) + isnull(bonus, 0) + isnull(hra, 0)from yourtablenamehere Peter LarssonHelsingborg, Sweden
Harsh AthalyeIndia."Nothing is Impossible" |
 |
|
|
amalshah71
Starting Member
9 Posts |
Posted - 2006-12-06 : 06:41:54
|
| thnk u harsh,peso.....that helped and made me understand...before this i had never heard of a function isnull(col_name,something)i could infer that 0 replaces a data value where it encounters nullit would be helpful if i get to know more abt these kind of functions...may be some link abt functions in sql-2000help appreciatedcheers |
 |
|
|
DonAtWork
Master Smack Fu Yak Hacker
2167 Posts |
Posted - 2006-12-06 : 06:49:00
|
| check BOL (Books On Line). It was installed along with your SQL SERVER. BOL is the help for SQL SERVER.[Signature]For fast help, follow this link:http://weblogs.sqlteam.com/brettk/archive/2005/05/25.aspxLearn SQLhttp://www.sql-tutorial.net/ http://www.firstsql.com/tutor.htm http://www.w3schools.com/sql/default.asp |
 |
|
|
Page47
Master Smack Fu Yak Hacker
2878 Posts |
Posted - 2006-12-06 : 08:28:28
|
| In your database design, you should make Salary, Bonus and HRA not nullable and include a default constraint to set them each to 0. Then in your DML, you won't need to worry about nullability. Usually best practice is to not allow nulls in the database.Jayto here knows when |
 |
|
|
|
|
|
|
|