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
 SQL Server 2000 Forums
 Transact-SQL (2000)
 Dynamic calculation

Author  Topic 

mosheallen
Starting Member

1 Post

Posted - 2005-11-28 : 06:54:49
Hi,
I get different values and a calculation from a query and need to bring them all together to make another calculation.
@PRICE,@TIME,@CALC,@TOTAL
@PRICE = 3
@TIME = 5
@CALC = '* .5'
@TOTAL = (@PRICE @CALC) * @TIME
I tried to use the exec command, but couldn't get it to work
How can I do this using Transact SQL?

Thank you,
Moshe

surendrakalekar
Posting Yak Master

120 Posts

Posted - 2005-11-28 : 07:15:31
Not understand exactlly but try this ....
Declare @PRICE int ,@TIME int ,@CALC float, @TOTAL float
Select @PRICE = 3
Select @TIME = 5
Select @CALC = 0.5
Select @TOTAL = (@PRICE * @CALC) * @TIME
Select @Price, @Time, @calc , @total

HTH

Surendra
Go to Top of Page

sqlmember
Starting Member

7 Posts

Posted - 2005-11-28 : 07:28:03
do you want to do like this
declare @PRICE int,@TIME int,@CALC varchar(255),@TOTAL int, @str varchar(500)
set @PRICE = 3
set @TIME = 5
set @CALC = '* .5'
set @str = '('+cast(@PRICE as varchar) + @CALC +') * '+cast(@TIME as varchar)
print @str
exec('select '+@str)

-Khurram Iqbal
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2005-11-28 : 08:20:45
>>I tried to use the exec command, but couldn't get it to work

Why did you use Dynamic SQL?

Madhivanan

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

- Advertisement -