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.
| Author |
Topic |
|
tchinedu
Yak Posting Veteran
71 Posts |
Posted - 2006-07-18 : 10:44:23
|
| I have a Table to hold constants for calculation in my stored proc:DDL:create table CalcFactors( VerName varchar(10) not null, FieldName varchar(30) not null, FieldValue float not null constraint PK_Factors primary key(VerType, FieldName) clustered)Now I have inserted 50 rows of data into the table keeping track of thier field namesNow to select I'm doing:declare @Const1 float, declare @const2 Float, declare @const3 float ... etc (50 variables declared)select @Const1=FieldValue from CalcFactors where FieldName='Constant1'Select @Const2=FieldValue from CalcFactors where FieldName='Constant2'etc...50 timesis there a better way to do this selection |
|
|
RyanRandall
Master Smack Fu Yak Hacker
1074 Posts |
Posted - 2006-07-18 : 12:21:30
|
quote: is there a better way to do this selection
Not really for this low-level problem. Perhaps if you describe the bigger picture we can suggest a better overall approach.One option for the described problem is to do something like this...select @Const1 = max(case when FieldName = 'Constant1' then FieldValue end), @Const2 = max(case when FieldName = 'Constant2' then FieldValue end), @Const3 = max(case when FieldName = 'Constant3' then FieldValue end)from CalcFactors Ryan Randallwww.monsoonmalabar.com London-based IT consultancy Solutions are easy. Understanding the problem, now, that's the hard part. |
 |
|
|
|
|
|