您的情況確實需要更好的描述。
但是從基礎開始,您需要選擇1個單位作爲數據庫的基本單位。 (好,所以1個電阻器單位,1個電容器單位) 將所有值存儲在該基本單位中。 存儲「外界」單元是一個單獨的列。
既然你所有的值都在同一個單位,你可以對它們進行計算。 當是輸出到外部世界的時候,使用查找表來轉換爲任何需要的單位。
因此:
create table test.resistors(
name nvarchar(1000)
,value int
,unit smallint
)
insert into test.resistors([name],[value],[unit])
values('2 milliOhms resistor',2,1)
insert into test.resistors([name],[value],[unit])
values('2000 Ohm resistor',2,3)
insert into test.resistors([Name],[value],[unit])
values('10 Meg resistor',10,4)
create table test.resistorUnits(
code smallint identity(1,1)
,name nvarchar(60)
,Ohms float
)
insert into test.resistorUnits([name],[Ohms])
values('m',.0001)
insert into test.resistorUnits([name],[Ohms])
values('Ohms',1)
insert into test.resistorUnits([name],[Ohms])
values('k',1000)
insert into test.resistorUnits([name],[Ohms])
values('M',1000000)
select
R.name, R.value * U.Ohms as [Value in Ohms], cast(R.value as nvarchar) + ' ' + U.name as [Original Value]
from test.resistors R inner join test.resistorUnits U
on R.unit = U.code
幫助我們幫助您 - 請分享你的表結構,一些示例數據,你正在試圖獲得該樣品 – Mureinik
只要給每個表隱式SI單位的結果。 –
只是爲了澄清:SI字首是值的一部分,例如「1u」或存儲在單獨的列中。我想了解你的問題是否是關於解析值的? – Alex