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
 Multiply Temp variable with 1000

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
Go to Top of Page

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 NULL
SET @income = 0
else
set @income = select income * 1000 from tablename where id= 1234)
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-10-07 : 14:08:28
didnt the solution work for u?
Go to Top of Page

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 NULL
SET @income = 0
else
set @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)
Go to Top of Page

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 NULL
SET @income = 0
else
set @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
Go to Top of Page

Chinni
Yak Posting Veteran

95 Posts

Posted - 2008-10-07 : 14:27:27
yes I tried this...this worked with out if..else
Go to Top of Page

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 NULL
SET @income = 0
else
set @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)*1000

Madhivanan

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

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 NULL
SET @income = 0
else
set @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)*1000

Madhivanan

Failing to plan is Planning to fail


sorry Madhi.didnt understand that. cant we use it in single step?
Go to Top of Page

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 NULL
SET @income = 0
else
set @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)*1000

Madhivanan

Failing 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,45
declare @income decimal(12,2)

--Visakh
SELECT @income=COALESCE(@income,0)*1000 FROM @incomes WHERE id=1234
SELECT @income

--Madhivanan
SELECT @income=@income FROM @incomes WHERE id=1234
SELECT COALESCE(@income,0)*1000


Madhivanan

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

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-10-09 : 04:40:48
Ah...sorry i understood Madhi. thanks
Go to Top of Page
   

- Advertisement -