Showing posts with label expressions. Show all posts
Showing posts with label expressions. Show all posts

Sunday, February 12, 2012

Are there no "Computed" column types? For storing expressions (results of other fields

I just read something interesting here: http://www.informit.com/library/content.asp?b=STY_Sql_Server_7&seqNum=101

A column type that helds an expression, and in queries returns the results.

That sounds excelent in my database, to save some code in my client applications. E.g adding price totals, and taxes of an order.

I can't find any info about this in later versions of SQL server. Is this not possible anymore?

not really necessary. . . create a view.

create table LineItem(itemId, price, quantity)

create view LineItemWTax as select itemid, price, quantity, price*quantity*0.045 as Tax

select * from LineItemWTax

you can also create a function:

create function CalculateTax(@.price money, @.quantity int, @.rate as decimal (3,3))
returns money
as
begin
return @.price * @.quantity * @.rate
end
go
select itemid, price, quantity, dbo.CalculateTax(price, quantity, .045) from LineItem

|||Thanks, thats probably a better way i guess :)

are there any sample models that i can download with some complex filters/expressions etc?

hi there

someone else actually asked the above question but it would certainly be helpful for us newbies!

cheers

Dianne

dont know whether it has complex filters you are asking,but if you install sql server 2005 samples it comes with some sample report models.|||

thanks I have been using some of those

cheers

Jewel