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 |
gamaz
Posting Yak Master
104 Posts |
Posted - 2008-06-09 : 13:00:13
|
Hi,I have a few lines of code where I am trying to fill the variable @ROI based on condition of a field. DECLARE @ROI varchar(30) If (dbo_PWOPayback.AnnualVolumePer1000 = 0) set @ROI = 0Thus @ROI should give output based on the field. If there are ten matches ROI should output ten values.However I am getting the following error when I am trying to run the above code from QAThe column prefix 'dbo_PWOPayback' does not match with a table name or alias name used in the query.Any help is appreciated. Physically there is dbo_PWOPayback in the system. |
|
jimf
Master Smack Fu Yak Hacker
2875 Posts |
Posted - 2008-06-09 : 13:07:54
|
@ROI can only hold one value at a time, perhaps you need a table-valued function? Explain more on what you want to accomplish.JimDECLARE @ROI varchar(30) set @ROI = dbo_PWOPayback.AnnualVolumePer1000 from dbo_PWOPaybackwhere "this being true of dbo_PWOPayback means only one value returned" |
 |
|
gamaz
Posting Yak Master
104 Posts |
Posted - 2008-06-09 : 13:34:22
|
OK I have a table named dbo_PWOPayback. This has few fields and aslo field AnnualVolumePer1000. The values of the AnnualVolumePer1000 is as follows100200015000501000NOW I need to calculate ROI based on the condition if (dbo_PWOPayback.AnnualVolumePer1000 = 0) in the above tablethen ROI should have a value of 0 else it should have a value of 1. Thus I am looking for a value of ROIout of the calculation asROI110100110. Hope I could explain what I intend to do. Thanks for your help. |
 |
|
jimf
Master Smack Fu Yak Hacker
2875 Posts |
Posted - 2008-06-09 : 13:43:44
|
set @ROI = CASE WHEN ISNULL(dbo_PWOPayback.AnnualVolumePer1000,0) > THEN 1 ELSE 0 END from dbo_PWOPaybackBut you still have to get just one value at a time or you'll get an error. If ROI is a field in the table thenUPDATE dbo_PWOPaybackROI = CASE WHEN ISNULL(dbo_PWOPayback.AnnualVolumePer1000,0) > 0 THEN 1 ELSE 0 END I'm still not completely clear what you're trying to accomplish |
 |
|
gamaz
Posting Yak Master
104 Posts |
Posted - 2008-06-09 : 14:54:10
|
jimfI need to create a stored procedure and get the value of ROI field based on a few calculations. I guess the best approach is to create a temporary table, adding a ROI field to the #tmp_dbo_PWOPayback table and update it in accodance with your approach. Hope I could explain. Thanks again. |
 |
|
|
|
|