473,397 Members | 1,974 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,397 software developers and data experts.

Caculated Fields in a Query

Hi Guys,

Sorry if this is a really stupid question. I am trying to upsize my Access database to SQL server. When I used the Access upsizing wizard, some of my queries didn't get upsized so I am building them as views in SQL server. I am having problems doing calculations on fields within the query. For instance, I need to have the following calculation performed on the query below. I want it contained within this query because it is the control source of one of my reports:

Expand|Select|Wrap|Line Numbers
  1. Round([DentalYESNO]*(15*[Area Factor]*[Network Factor]*[Trend Factor]*[Primary Age Gender Factor]*1.42857+[Primary Rider Factor]),2) AS [Primary Rate], 
would be the next field in this query:

Expand|Select|Wrap|Line Numbers
  1. SELECT     CASE WHEN dbo.[Final Action].[Initial Pay Mode] = 'Monthly' THEN 1 WHEN dbo.[Final Action].[Initial Pay Mode] = 'Quarterly' THEN 3 WHEN dbo.[Final Action].[Initial Pay Mode]
  2.                        = 'SemiAnnual' THEN 6 ELSE 0 END AS ModalFactor, CASE WHEN dbo.[Final Action].[Spouse Build Rate] > 0 AND 
  3.                       dbo.[Final Action].[Spouse Non-Build Rate] > 0 THEN (dbo.[Final Action].[Spouse Non-Build Rate] - 1) + (dbo.[Final Action].[Spouse Build Rate] - 1) 
  4.                       + 1 ELSE 0 END AS [Spouse Total Rateup], CASE WHEN dbo.[Final Action].[Primary Build Rate] > 0 AND 
  5.                       dbo.[Final Action].[Primary Non-Build Rate] > 0 THEN (dbo.[Final Action].[Primary Non-Build Rate] - 1) + (dbo.[Final Action].[Primary Build Rate] - 1) 
  6.                       + 1 ELSE 0 END AS [Primary Total Rateup], dbo.[PR Only Info].[List Name], dbo.[PR Only Info].[Prospect Number], dbo.[Final Action].Fname, 
  7.                       dbo.[Final Action].LNAme, dbo.[Dental Area Factors].[Area Factor], dbo.[Dental Network Factors].[Network Factor], dbo.[Final Action].[FPMC no Rateup],
  8.                           (SELECT     [Trend Factor]
  9.                             FROM          dbo.[Dental Trend Factors]
  10.                             WHERE      dbo.[Dental Trend Factors].State = CASE WHEN dbo.[Final Action].[Issue State] = 'FL' THEN 'FL' ELSE 'GN' END AND 
  11.                                                    dbo.[Final Action].[Eff Date] BETWEEN dbo.[Dental Trend Factors].[Eff Date] AND dbo.[Dental Trend Factors].[End Date]) AS [Trend Factor], 
  12.                       CASE WHEN dbo.[Final Action].[Dental Product] = 1 THEN 1 ELSE 0 END AS DentalYesNo, dbo.[Final Action].[Dental Product],
  13.                           (SELECT     [Age Gender Factor]
  14.                             FROM          dbo.[Dental Age Gender Rider Factors]
  15.                             WHERE      dbo.[Dental Age Gender Rider Factors].state = CASE WHEN dbo.[Final Action].[Issue State] = 'FL' THEN 'FL' ELSE 'GN' END AND 
  16.                                                    dbo.[Final Action].Age BETWEEN dbo.[Dental Age Gender Rider Factors].[Age From] AND 
  17.                                                    dbo.[Dental Age Gender Rider Factors].[Age to] AND dbo.[Final Action].Gender = dbo.[Dental Age Gender Rider Factors].Gender) 
  18.                       AS [Primary Age Gender Factor],
  19.                           (SELECT     [Rider Factor]
  20.                             FROM          dbo.[Dental Age Gender Rider Factors]
  21.                             WHERE      dbo.[Dental Age Gender Rider Factors].state = CASE WHEN dbo.[Final Action].[Issue State] = 'FL' THEN 'FL' ELSE 'GN' END AND 
  22.                                                    dbo.[Final Action].Age BETWEEN dbo.[Dental Age Gender Rider Factors].[Age From] AND 
  23.                                                    dbo.[Dental Age Gender Rider Factors].[Age to] AND dbo.[Final Action].Gender = dbo.[Dental Age Gender Rider Factors].Gender) 
  24.                       AS [Primary Rider Factor]
  25. FROM         dbo.[Dental Network Factors] INNER JOIN
  26.                       dbo.[Dental Area Factors] ON dbo.[Dental Network Factors].State = dbo.[Dental Area Factors].State INNER JOIN
  27.                       dbo.[Dental ZIP Codes] ON dbo.[Dental Network Factors].State = dbo.[Dental ZIP Codes].State AND 
  28.                       dbo.[Dental Network Factors].[State Region] = dbo.[Dental ZIP Codes].[State Region] AND 
  29.                       dbo.[Dental Area Factors].State = dbo.[Dental ZIP Codes].State AND 
  30.                       dbo.[Dental Area Factors].[State Region] = dbo.[Dental ZIP Codes].[State Region] INNER JOIN
  31.                       dbo.[Final Action] ON dbo.[Dental ZIP Codes].ZIP = dbo.[Final Action].Zip INNER JOIN
  32.                       dbo.[PR Only Info] ON dbo.[Final Action].[Master ID] = dbo.[PR Only Info].ID
When I try to add the calculated field, I get an error message that says "'Trend Factor' in expression is not part of the query." This is my first experience with SQL Server, so again, I apologize if I'm missing something really obvious.

Thanks,
Josh
Dec 11 '06 #1
1 1708
almaz
168 Expert 100+
Trend Factor is an alias for certain computed column. You cannot use aliases in the statements of the same select query, so you may write it as following:
Expand|Select|Wrap|Line Numbers
  1. select *, Round([DentalYESNO]*(15*[Area Factor]*[Network Factor]*[Trend Factor]*[Primary Age Gender Factor]*1.42857+[Primary Rider Factor]),2) AS [Primary Rate]
  2. from
  3.   ( YOUR_BIG_SELECT_STATEMENT
  4.   ) Source
Dec 11 '06 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Grim Reaper | last post by:
I asked this question, earlier, and received an answer that I am not sure about how to do. Basically, I am printing mailing labels with a "Sorting/Grouping" section that groups the label types...
5
by: Megan | last post by:
Hi everybody- I'm helping a friend with a music database. She has an old one and is creating a new one. She wants to compare records and fields in the old database with records and fields in the...
5
by: ND | last post by:
I need to create a separate field from 4 fields, "street address", "city", "State" and "zip code". For example, Street address - 100 Forest Street City - Seattle State - WA Zip - 05555 ...
3
by: google | last post by:
I have a database with four table. In one of the tables, I use about five lookup fields to get populate their dropdown list. I have read that lookup fields are really bad and may cause problems...
0
by: Proteus | last post by:
Hi, I'm using access 97 on windows 98. I have table with 162 fields in it. I need to withdraw this information in a (totals) query with 164 fields (162 "avg" fields and 2 "count" fields). When I...
8
by: Maxi | last post by:
There is a lotto system which picks 21 numbers every day out of 80 numbers. I have a table (name:Lotto) with 22 fields (name:Date,P1,P2....P21) Here is the structure and sample data: ...
6
by: Mark | last post by:
Hello. I have an MS Access 2000 form whose fields I need to read and write from VBA. The fields are data-bound, using a query that has been defined and saved in my Access database. The query...
9
by: Jimbo | last post by:
Hello, I have a user request to build a form in an Access database where the user can check off specific fields to pull in a query. For example, let's say I have 10 fields in a table. The user...
3
by: fstenoughsnoopy | last post by:
Ok the complete story. I have a Contact Table, Query and Form, that are used to input and store the contact info for customers. They have FirstName, LastName and Address as the primary key...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.