[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

What is causing this errand in the stored procedure. (Operand should contain 1 column(s))

Posted on 2013-12-26
1
Medium Priority
?
882 Views
Last Modified: 2013-12-26
I am trying to set myItemId so that I can use it in the concat query. Everything works fine until I add this row

  SET myItemID = (SELECT * FROM items i  WHERE i.name LIKE '%KW PRE FREE COOLING%');

Open in new window

It then gives me an error of Operand should contain 1 column(s)

Here is the query that I am working with

CREATE PROCEDURE reportFreeCoolingTempTable (
  IN fromDate VARCHAR (50),
  IN toDate   VARCHAR (50),
  IN timeZone VARCHAR (50)
)
BEGIN
  DECLARE startDate VARCHAR (50);
  DECLARE endDate   VARCHAR (50);
  DECLARE mylogID   INT;
  DECLARE myItemID  int;

  SET startDate = FROM_UNIXTIME(fromDate/1000);
  SET endDate   = FROM_UNIXTIME(toDate/1000);
  SET mylogID   = (SELECT logID FROM logs WHERE details LIKE 'FCT%' LIMIT 1);
  SET myItemID = (SELECT * FROM items i  WHERE i.name LIKE '%KW PRE FREE COOLING%');

  SET @sql = NULL;
    
  SET @sql = NULL;
  SET @sql = CONCAT(
  'SELECT @row:=@row+1 as rownum,
       a.logid ,   
       L1.recordId,
       L2.recordId as next_recordId,
       L1.completed,
       L2.completed as next_completed,
       L1.activityId,
       L2.activityId as next_activityId,
       IF(L1.activityId = L2.activityId,1,NULL) as isError,                           
       TIME_TO_SEC(TIMEDIFF(L2.completed, L1.completed)) / 3600 AS coolingHours,
       ((L1.item31985 - L1.item31987) * (time_to_sec(timediff(L2.completed, L1.completed)))) / 3600  AS kwDifference,
     ((L1.item31985 - L1.item31987) * (substr(l.details, instr(l.details , '':'' ) +1))) AS cost,
    ( (((L1.item31985 - L1.item31987) * (substr(l.details, instr(l.details , '':'' ) +1)))
    *(time_to_sec(timediff(L2.completed, L1.completed)) / 3600))) AS costT,
     time_to_sec(timediff(''', endDate, ''', ''', startDate, ''')) / 3600 AS totalTimeRange,
    CONVERT_TZ(''', startDate, ''', ''UTC'', ''', timeZone, ''') AS startingDate, 
    CONVERT_TZ(''', endDate, ''', ''UTC'', ''', timeZone, ''') AS endingDate,
    DATABASE() AS databaseName

FROM
    (SELECT @row:=0)R,
    (SELECT T1.completed,
       (SELECT MIN(completed)
         FROM log1644
         WHERE completed > T1.completed) AS next_completed
      FROM log',mylogID, ' T1
      ORDER BY T1.completed
     )TimeOrder
        LEFT JOIN log', mylogID, ' L1 ON (L1.completed = TimeOrder.completed)
        LEFT JOIN log', mylogID, ' L2 ON (L2.completed = TimeOrder.next_completed)
        LEFT JOIN activities a ON L1.activityId = a.activityId
        LEFT JOIN logs l ON a.logId = l.logId
        Left Join items i ON l.logId = i.logId AND i.name LIKE ''%KW%''
    WHERE i.itemID = 31985  
        AND L1.completed BETWEEN ''', startDate, ''' AND ''', endDate, '''
ORDER BY L1.completed');
    
        
        
 PREPARE stmt FROM @sql;
 EXECUTE stmt;
 DEALLOCATE PREPARE stmt;
END //


DELIMITER ;

Open in new window

0
Comment
Question by:portlight
1 Comment
 
LVL 33

Accepted Solution

by:
snoyes_jw earned 2000 total points
ID: 39740605
You can't set a variable to contain a row. Change the SELECT * to select only a single column, like SELECT id.
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
When table data gets too large to manage or queries take too long to execute the solution is often to buy bigger hardware or assign more CPUs and memory resources to the machine to solve the problem. However, the best, cheapest and most effective so…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses
Course of the Month18 days, 13 hours left to enroll

834 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