Solved

SQL Calculation Error

Posted on 2009-05-09
14
329 Views
Last Modified: 2012-05-06
Hi Experts,

My sql calculation keeps giving me an error.

Microsoft OLE DB Provider for SQL Server error '80040e14'

Invalid column name 'dreamID'.

/gmmcPub/dreamsReview.asp, line 62

I'm trying to figure out why I'm getting this error.
<%
Dim rsDreamsCalculate__MMColParam
rsDreamsCalculate__MMColParam = "1"
If (Session("MM_userID") <> "") Then 
  rsDreamsCalculate__MMColParam = Session("MM_userID")
End If
%>
<%
Dim rsDreamsCalculate
Dim rsDreamsCalculate_cmd
Dim rsDreamsCalculate_numRows
 
Set rsDreamsCalculate_cmd = Server.CreateObject ("ADODB.Command")
rsDreamsCalculate_cmd.ActiveConnection = MM_connGMMCdata_STRING
rsDreamsCalculate_cmd.CommandText = "SELECT dreamID, memberID, dreamDate, InHowManyMonths, HavingDream1, HavingDream2, HavingDream3,  HavingDream4, HavingDream5, BeingDream1, BeingDream1ToDo, BeingDream2, BeingDream2ToDo, BeingDream3, BeingDream3ToDo, BeingDream4, BeingDream4ToDo, BeingDream5, BeingDream5ToDo, DoingDream1, DoingDream2, DoingDream3, DoingDream4, DoingDream5, StepsNow, Tomorrow, NextDay, TMI, TDI, HavingDreamTotalCost, BeingDreamTotalCost, DoingDreamTotalCost, TotalDreamCost, COALESCE(HavingDream1Cost, 0) + COALESCE(HavingDream2Cost, 0) + COALESCE(HavingDream3Cost, 0) + COALESCE(HavingDream4Cost, 0) + COALESCE(HavingDream5Cost, 0)  as HavingDreams , COALESCE(BeingDream1Cost, 0) + COALESCE(BeingDream2Cost, 0) + COALESCE(BeingDream3Cost, 0) + COALESCE(BeingDream4Cost, 0) + COALESCE(BeingDream5Cost, 0) as BeingDreams , COALESCE(DoingDream1Cost, 0) + COALESCE(DoingDream2Cost, 0) +  COALESCE(DoingDream3Cost, 0) + COALESCE(DoingDream4Cost, 0) + COALESCE(DoingDream5Cost, 0) as DoingDreams --grandtotal=havingdreams+beingdreams+doingdreams FROM dbo.dreams WHERE memberID = ?" 
rsDreamsCalculate_cmd.Prepared = true
rsDreamsCalculate_cmd.Parameters.Append rsDreamsCalculate_cmd.CreateParameter("param1", 3, 1, -1, rsDreamsCalculate__MMColParam) ' adInteger
 
Set rsDreamsCalculate = rsDreamsCalculate_cmd.Execute
rsDreamsCalculate_numRows = 0
%>

Open in new window

0
Comment
Question by:GMMC_man
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
14 Comments
 
LVL 75

Expert Comment

by:Aneesh Retnakaran
ID: 24346874
seems like the table 'Dreams' doesnt contain the column 'DreamID'. it may be mispelled
0
 
LVL 31

Expert Comment

by:RiteshShah
ID: 24346894
yes, DremaID is either mispelled or not exists in table "Dream", can you double check it once?
0
 

Author Comment

by:GMMC_man
ID: 24347946
I've checked and checked. dreamID is how the field is spelled. It is an auto increment id integer.
0
Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

 
LVL 31

Expert Comment

by:RiteshShah
ID: 24348298
hhmmmm, I gotcha....... try below in your code.
"SELECT dreamID, memberID, dreamDate, InHowManyMonths, HavingDream1, HavingDream2, HavingDream3,  HavingDream4, HavingDream5, BeingDream1, BeingDream1ToDo, BeingDream2, BeingDream2ToDo, BeingDream3, BeingDream3ToDo, BeingDream4, BeingDream4ToDo, BeingDream5, BeingDream5ToDo, DoingDream1, DoingDream2, DoingDream3, DoingDream4, DoingDream5, StepsNow, Tomorrow, NextDay, TMI, TDI, HavingDreamTotalCost, BeingDreamTotalCost, DoingDreamTotalCost, TotalDreamCost, COALESCE(HavingDream1Cost, 0) + COALESCE(HavingDream2Cost, 0) + COALESCE(HavingDream3Cost, 0) + COALESCE(HavingDream4Cost, 0) + COALESCE(HavingDream5Cost, 0)  as HavingDreams , COALESCE(BeingDream1Cost, 0) + COALESCE(BeingDream2Cost, 0) + COALESCE(BeingDream3Cost, 0) + COALESCE(BeingDream4Cost, 0) + COALESCE(BeingDream5Cost, 0) as BeingDreams , COALESCE(DoingDream1Cost, 0) + COALESCE(DoingDream2Cost, 0) +  COALESCE(DoingDream3Cost, 0) + COALESCE(DoingDream4Cost, 0) + COALESCE(DoingDream5Cost, 0) as DoingDreams --grandtotal=havingdreams+beingdreams+doingdreams FROM dbo.dreams WHERE memberID = ?" 

Open in new window

0
 
LVL 31

Expert Comment

by:RiteshShah
ID: 24348307
sorry, use this one.  typo in above.
"SELECT dreamID, memberID, dreamDate, InHowManyMonths, HavingDream1, HavingDream2, HavingDream3,  HavingDream4, HavingDream5, BeingDream1, BeingDream1ToDo, BeingDream2, BeingDream2ToDo, BeingDream3, BeingDream3ToDo, BeingDream4, BeingDream4ToDo, BeingDream5, BeingDream5ToDo, DoingDream1, DoingDream2, DoingDream3, DoingDream4, DoingDream5, StepsNow, Tomorrow, NextDay, TMI, TDI, HavingDreamTotalCost, BeingDreamTotalCost, DoingDreamTotalCost, TotalDreamCost, COALESCE(HavingDream1Cost, 0) + COALESCE(HavingDream2Cost, 0) + COALESCE(HavingDream3Cost, 0) + COALESCE(HavingDream4Cost, 0) + COALESCE(HavingDream5Cost, 0)  as HavingDreams , COALESCE(BeingDream1Cost, 0) + COALESCE(BeingDream2Cost, 0) + COALESCE(BeingDream3Cost, 0) + COALESCE(BeingDream4Cost, 0) + COALESCE(BeingDream5Cost, 0) as BeingDreams , COALESCE(DoingDream1Cost, 0) + COALESCE(DoingDream2Cost, 0) +  COALESCE(DoingDream3Cost, 0) + COALESCE(DoingDream4Cost, 0) + COALESCE(DoingDream5Cost, 0) as DoingDreams, grandtotal=havingdreams+beingdreams+doingdreams FROM dbo.dreams WHERE memberID = ?" 

Open in new window

0
 

Author Comment

by:GMMC_man
ID: 24348372
Now getting error - Invalid column name 'havingdreams'.
0
 
LVL 31

Expert Comment

by:RiteshShah
ID: 24348375
can you show me your table structure? do you have "havingdreams' column?
0
 

Author Comment

by:GMMC_man
ID: 24348399
no havingdreams is created in sql query
0
 
LVL 31

Expert Comment

by:RiteshShah
ID: 24348402
try this.
SELECT 
dreamID, 
memberID, 
dreamDate, 
InHowManyMonths, 
HavingDream1, 
HavingDream2, 
HavingDream3,  
HavingDream4, 
HavingDream5, 
BeingDream1, 
BeingDream1ToDo, 
BeingDream2, 
BeingDream2ToDo, 
BeingDream3, 
BeingDream3ToDo, 
BeingDream4, 
BeingDream4ToDo, 
BeingDream5, 
BeingDream5ToDo, 
DoingDream1, 
DoingDream2, 
DoingDream3, 
DoingDream4, 
DoingDream5, 
StepsNow, 
Tomorrow, 
NextDay, 
TMI, 
TDI, 
COALESCE(HavingDream1 , 0) + COALESCE(HavingDream2 , 0) + COALESCE(HavingDream3 , 0) + COALESCE(HavingDream4 , 0) + COALESCE(HavingDream5 , 0)  as HavingDreamsTotal , 
 
COALESCE(BeingDream1 , 0) + COALESCE(BeingDream2 , 0) + COALESCE(BeingDream3 , 0) + COALESCE(BeingDream4 , 0) + COALESCE(BeingDream5 , 0) as BeingDreamsTotal , 
 
COALESCE(DoingDream1 , 0) + COALESCE(DoingDream2 , 0) +  COALESCE(DoingDream3 , 0) + COALESCE(DoingDream4 , 0) + COALESCE(DoingDream5 , 0) as DoingDreamsTotal,
 
grandtotal=HavingDreamsTotal+BeingDreamsTotal+DoingDreamsTotal FROM dbo.dreams WHERE memberID = ?

Open in new window

0
 

Author Comment

by:GMMC_man
ID: 24348693
Still getting error
Invalid column name 'HavingDreamsTotal'.

I removed grandtotal line and got this error
Microsoft OLE DB Provider for SQL Server error '80040e07'

Conversion failed when converting the varchar value 'A fully functional church' to data type int.

/gmmcPub/dreamsReview.asp, line 64
0
 
LVL 31

Accepted Solution

by:
RiteshShah earned 400 total points
ID: 24348702
in your original logic, you were trying to total something but you might not have numeric value in the fields you are making total rather it has value in string like 'A gully functional church' so it can't be use with addition or subtraction etc. have a look at this.
SELECT 
dreamID, 
memberID, 
dreamDate, 
InHowManyMonths, 
HavingDream1, 
HavingDream2, 
HavingDream3,  
HavingDream4, 
HavingDream5, 
BeingDream1, 
BeingDream1ToDo, 
BeingDream2, 
BeingDream2ToDo, 
BeingDream3, 
BeingDream3ToDo, 
BeingDream4, 
BeingDream4ToDo, 
BeingDream5, 
BeingDream5ToDo, 
DoingDream1, 
DoingDream2, 
DoingDream3, 
DoingDream4, 
DoingDream5, 
StepsNow, 
Tomorrow, 
NextDay, 
TMI, 
TDI 
FROM dbo.dreams WHERE memberID = ?

Open in new window

0
 
LVL 5

Expert Comment

by:satheeshm
ID: 24349256
Hi,

Can you please post your table structure.

Thanks,
Satheesh M
0
 
LVL 2

Assisted Solution

by:dzex13
dzex13 earned 100 total points
ID: 24349344
--grandtotal=havingdreams+beingdreams+doingdreams

Replace This string by:

COALESCE(HavingDream1 , 0) + COALESCE(HavingDream2 , 0) + COALESCE(HavingDream3 , 0) + COALESCE(HavingDream4 , 0) + COALESCE(HavingDream5 , 0)  +
COALESCE(BeingDream1 , 0) + COALESCE(BeingDream2 , 0) + COALESCE(BeingDream3 , 0) + COALESCE(BeingDream4 , 0) + COALESCE(BeingDream5 , 0) +
COALESCE(DoingDream1 , 0) + COALESCE(DoingDream2 , 0) +  COALESCE(DoingDream3 , 0) + COALESCE(DoingDream4 , 0) + COALESCE(DoingDream5 , 0) as GrandTotal

0
 

Author Comment

by:GMMC_man
ID: 24349628
That worked - Thanks.

Here's the final code. I was calculating text fields which was throwing an error. After adding Cost to each dream it worked fine. Thanks.

SELECT dreamID, memberID, dreamDate, InHowManyMonths, HavingDream1, HavingDream2, HavingDream3,  HavingDream4, HavingDream5, BeingDream1, BeingDream1ToDo, BeingDream2, BeingDream2ToDo, BeingDream3, BeingDream3ToDo, BeingDream4, BeingDream4ToDo, BeingDream5, BeingDream5ToDo, DoingDream1, DoingDream2, DoingDream3, DoingDream4, DoingDream5, StepsNow, Tomorrow, NextDay, TMI, TDI, COALESCE(HavingDream1Cost , 0) + COALESCE(HavingDream2Cost , 0) + COALESCE(HavingDream3Cost , 0) + COALESCE(HavingDream4Cost , 0) + COALESCE(HavingDream5Cost , 0)  as HavingDreamsTotal , COALESCE(BeingDream1Cost , 0) + COALESCE(BeingDream2Cost , 0) + COALESCE(BeingDream3Cost , 0) + COALESCE(BeingDream4Cost , 0) + COALESCE(BeingDream5Cost , 0) as BeingDreamsTotal , COALESCE(DoingDream1Cost , 0) + COALESCE(DoingDream2Cost , 0) +  COALESCE(DoingDream3Cost , 0) + COALESCE(DoingDream4Cost , 0) + COALESCE(DoingDream5Cost , 0) as DoingDreamsTotal, COALESCE(HavingDream1Cost , 0) + COALESCE(HavingDream2Cost , 0) + COALESCE(HavingDream3Cost , 0) + COALESCE(HavingDream4Cost , 0) + COALESCE(HavingDream5Cost , 0)  + COALESCE(BeingDream1Cost , 0) + COALESCE(BeingDream2Cost , 0) + COALESCE(BeingDream3Cost , 0) + COALESCE(BeingDream4Cost , 0) + COALESCE(BeingDream5Cost , 0) + COALESCE(DoingDream1Cost , 0) + COALESCE(DoingDream2Cost , 0) +  COALESCE(DoingDream3Cost , 0) + COALESCE(DoingDream4Cost , 0) + COALESCE(DoingDream5Cost , 0) as GrandTotal FROM dbo.dreams WHERE memberID = ?
0

Featured Post

SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Confronted with some SQL you don't know can be a daunting task. It can be even more daunting if that SQL carries some of the old secret codes used in the Ye Olde query syntax, such as: (+)     as used in Oracle;     *=     =*    as used in Sybase …
Composite queries are used to retrieve the results from joining multiple queries after applying any filters. UNION, INTERSECT, MINUS, and UNION ALL are some of the operators used to get certain desired results.​
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

729 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question