473,465 Members | 1,373 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Not able to execute insert query using EXECUTE command in procedure

1 New Member
Hi

I am not able to compile the procedure in postgresql. I am getting syntax error when compiling the below PROCEDURE
Expand|Select|Wrap|Line Numbers
  1. CREATE OR REPLACE PROCEDURE populate_data_to_table(tableName IN text,employeecolumn IN text, status OUT integer) AS 
  2.  
  3. Declare 
  4. table_data RECORD;
  5. employeeCnt INTEGER;
  6. employeeinsert INTEGER;
  7. table_Name text;
  8. insertquery text;
  9. updatequery text;
  10. selectquery text;
  11.  
  12. BEGIN
  13. RAISE NOTICE 'begin';
  14.  
  15. RAISE NOTICE 'tableName % ',tableName;
  16.  
  17. selectquery:='SELECT '|| employeecolumn ||' as employeeid, COUNT(*)
  18.   FROM '|| tableName ||' c
  19.   GROUP BY c.'||employeecolumn||'';
  20.   RAISE NOTICE 'selectquery % ',selectquery;
  21.  
  22. FOR table_data IN 
  23.  
  24. EXECUTE selectquery 
  25.  
  26. LOOP 
  27. RAISE NOTICE 'loop data %',table_data.employeeid;
  28. RAISE NOTICE 'loop COUNT %',table_data.COUNT;
  29.   select count(empid) into employeeCnt from temp_table_data where empid = table_data.employeeid;
  30. RAISE NOTICE 'data Count %', employeeCnt;
  31.  
  32. if employeeCnt = 0 then
  33. RAISE NOTICE 'data not found';
  34. insertquery := 'INSERT INTO temp_table_data(empid, '||tableName ||',last_updated_date) 
  35. values (1,1,sysdate)';
  36. RAISE NOTICE 'insertquery %',insertquery;
  37.  
  38. EXECUTE insertquery; --not able to execute this getting syntax error 
  39.  
  40. else
  41. RAISE NOTICE 'data found';
  42. updatequery :='UPDATE temp_table_data set '|| tableName ||'= table_data.COUNT,
  43. last_updated_date =sysdate where empid = table_data.employeeid';
  44. RAISE NOTICE 'updatequery %',updatequery;
  45. EXECUTE updatequery;
  46.  
  47. end if;
  48.  
  49. END LOOP;
  50.  
  51. COMMIT; 
  52.  
  53. status := 0;
  54.  
  55. EXCEPTION
  56.  
  57. WHEN others THEN 
  58.  
  59. status := -1; 
  60. RAISE NOTICE 'SQLERRM %',SQLERRM;
  61.  
  62. END
  63.  
ERROR: syntax error at or near "insertquery"
LINE 38: EXECUTE insertquery;
^
********** Error **********

ERROR: syntax error at or near "insertquery"
SQL state: 42601
Character: 1012

Can anyone tell me where I am doing wrong ?
Please help me to resolve this.

Thanks in advance.
Ravi
May 14 '14 #1
0 1395

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

Similar topics

1
by: Marcelo Moreira | last post by:
Hi all, Does somebody know how I can use the index service inside asp.net?? I want to execute a search query... Thank u all. Marcelo
5
by: Annie | last post by:
hello guys, I have little experience working with C# and MS Access ... I am having an insert query with one datetime field and a boolean and couple of text and number fields as below: ...
1
by: Marcelo Moreira | last post by:
Hi all, I want to execute a query making use of the index service provided with windows. How can I make this? It would also be great to know how I can manage (which class to use) my catalogs. ...
0
by: Hrvoje Vrbanc | last post by:
Hello all! I'm new to ASP.NET 2.0 and I tried connecting and inserting to a SQL database by using SqlDataSource control. I build an INSERT query using the query builder tool but I'm puzzled...
1
by: TheDataGuy | last post by:
Using MS ACCESS 2002 Problem - I developed a form, and within that FORM, I added a SEARCH BUTTON, and then I created a SUB-FORM, so when an end user clicks on the FORM it will POP-UP the SUB-FORM,...
1
by: sheenaa | last post by:
Hello Members, I m creating my application forms in ASP.Net 2005 C# using the backend SQL Server 2005. What i have used on forms :: ? On my first form i have used some...
1
by: =?Utf-8?B?RGV2YW4=?= | last post by:
Hi, I have a table adapter for a database with an insert query. I want to be able to get the PRIMARY key of the inserted record for that insert statement. I know that SCOPE_IDENTITY is the...
0
by: teckguan | last post by:
Hi everyone, I would like to ask how am I going to execute multiple scripts using UNIX command? I have found a command to execute. However, I cannot execute it. The command is db2 -txf <<EOF...
2
by: jrkarthi | last post by:
dim con As New SqlConnection("Data Source=.\SQLEXPRESS;AttachDbFilename=C:\KarthI\sample\db1\WindowsApplication1\WindowsApplication1\bin\Debug\phm_pharmacy.mdf;Integrated Security=True;Connect...
1
by: Marco van der M | last post by:
Hello everyone, I am trying to make an insert query that inserts information using form values and a query that gets the id from the name of a field in the form. I got a form that shows object...
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:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
1
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
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...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

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.