如何用SQL语句检索单位转换的数量计算啊?
例如 我有一种商品,存在数据库里有两中单位,检索那种商品的数量的时候,能不能自动把单位转换后再计算出数值来啊?
------解决方案--------------------create table a(name varchar(20),unit int)
insert into a select 'us ',8
insert into a select 'RMB ',1
insert into a select 'HK Dollar ',2
select * from a
alter function caculate(@num int,@name varchar(20))
RETURNS int
as
Begin
declare @Currency int
select @Currency = @num*unit from a where name = @name
return @Currency
end
select dbo.caculate(8, 'HK Dollar ')