| Author |
Topic |
|
Chinni
Yak Posting Veteran
95 Posts |
Posted - 2008-10-07 : 13:53:38
|
| SET @income =(select income from tablename where id= 1234) IF @INCOME IS NULL SET @income = 0 else set @income = (@income *1000)Need to multiply with 1000 if value exists ,if the field null zero |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-10-07 : 13:58:09
|
| SELECT @income=COALESCE(income,0)*1000 FROM tablename WHERE id=1234 |
 |
|
|
Chinni
Yak Posting Veteran
95 Posts |
Posted - 2008-10-07 : 14:02:08
|
| SET @income =(select income from tablename where id= 1234)IF @INCOME IS NULLSET @income = 0elseset @income = select income * 1000 from tablename where id= 1234) |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-10-07 : 14:08:28
|
| didnt the solution work for u? |
 |
|
|
Chinni
Yak Posting Veteran
95 Posts |
Posted - 2008-10-07 : 14:13:45
|
| yes it worked.Thanks SET @income =(select income from tablename where id= 1234)IF @INCOME IS NULLSET @income = 0elseset @income = (select COALESCE(income,0)*1000 from tablename where id= 1234)(this is in a fucntion with return value I need to set the value) |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-10-07 : 14:19:01
|
quote: Originally posted by Chinni yes it worked.Thanks SET @income =(select income from tablename where id= 1234)IF @INCOME IS NULLSET @income = 0elseset @income = (select @income =COALESCE(income,0)*1000 from tablename where id= 1234(this is in a fucntion with return value I need to set the value)
you just need the above code in blue alone. no need of if else |
 |
|
|
Chinni
Yak Posting Veteran
95 Posts |
Posted - 2008-10-07 : 14:27:27
|
| yes I tried this...this worked with out if..else |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2008-10-09 : 03:39:21
|
quote: Originally posted by visakh16
quote: Originally posted by Chinni yes it worked.Thanks SET @income =(select income from tablename where id= 1234)IF @INCOME IS NULLSET @income = 0elseset @income = (select @income =COALESCE(income,0)*1000 from tablename where id= 1234(this is in a fucntion with return value I need to set the value)
you just need the above code in blue alone. no need of if else
SELECT @income=income FROM tablename WHERE id=1234 SELECT COALESCE(@income,0)*1000MadhivananFailing to plan is Planning to fail |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-10-09 : 03:44:25
|
quote: Originally posted by madhivanan
quote: Originally posted by visakh16
quote: Originally posted by Chinni yes it worked.Thanks SET @income =(select income from tablename where id= 1234)IF @INCOME IS NULLSET @income = 0elseset @income = (select @income =COALESCE(income,0)*1000 from tablename where id= 1234(this is in a fucntion with return value I need to set the value)
you just need the above code in blue alone. no need of if else
SELECT @income=income FROM tablename WHERE id=1234 SELECT COALESCE(@income,0)*1000MadhivananFailing to plan is Planning to fail
sorry Madhi.didnt understand that. cant we use it in single step? |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2008-10-09 : 03:58:03
|
quote: Originally posted by visakh16
quote: Originally posted by madhivanan
quote: Originally posted by visakh16
quote: Originally posted by Chinni yes it worked.Thanks SET @income =(select income from tablename where id= 1234)IF @INCOME IS NULLSET @income = 0elseset @income = (select @income =COALESCE(income,0)*1000 from tablename where id= 1234(this is in a fucntion with return value I need to set the value)
you just need the above code in blue alone. no need of if else
SELECT @income=income FROM tablename WHERE id=1234 SELECT COALESCE(@income,0)*1000MadhivananFailing to plan is Planning to fail
sorry Madhi.didnt understand that. cant we use it in single step?
declare @incomes table(id int, income decimal(12,2))insert into @incomes select 124,45declare @income decimal(12,2)--VisakhSELECT @income=COALESCE(@income,0)*1000 FROM @incomes WHERE id=1234 SELECT @income--MadhivananSELECT @income=@income FROM @incomes WHERE id=1234 SELECT COALESCE(@income,0)*1000 MadhivananFailing to plan is Planning to fail |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-10-09 : 04:40:48
|
Ah...sorry i understood Madhi. thanks |
 |
|
|
|