I have to write a query with lot of computations. Is it a good idea to create indexed view with this computed columns instead of writing a stored proc? Thanks!!
It depends!
If you create an indexed view you'll be trading increased costs in terms of greaer storage space requirements and slower inserts, updates & deletes for increased speed of accessing these computed values. If you only want to use these values once or occassionally, you might be better off computing them on demand in a SP but, like I said, it depends!
There are other factors to consider to, including: over how many records do these computations need to execued? If it's just a few, the indexed view approach may not be appropriate because it may affect all rows unless you limit it with sutable WHERE/HAVING clauses - remember that an indexed view isn't parameterised.
I would only suggest an indexed view when you are dealing with a very high amount of records found in places like Datawarehouse or Datamarts. Here you will be doing much more reading of the data then writing to it so the index will help you more than hurt you.