Hello ...
I'm trying to create a Stored Procedure that receives two parameters (both are Date). The SP must create a View from a Select containing two JOIN and three WHERE conditions involving the two parameters.
I am working with DB2 9.7 FixPack 2 on Windows 7 32-bit and IBM Data Studio 2.2.
The problem I have is that by making the deployment of the SP returns the following error: COBR.SP_CREATEVIEWMOVCUSTOMER: 17: "STARTDATEMONITOR" is not valid in the context .. Where It is Used SQLCODE =- 206, SQLSTATE = 42703, DRIVER = 3.61.65
The code of my SP is as follows: -
CREATE PROCEDURE SP_CreateViewMovCustomer (StartDateMonitor IN DATE,
-
FinishDateMonitor IN DATE)
-
-
SPECIFIC SP_CreateViewMovCustomer
-
-
P1: BEGIN
-
-
If Exists (Select 1 From SYSIBM.SYSVIEWS Where Name = 'VIEWMOVCUSTOMER' and creator = 'Cobra')
-
Then
-
DROP VIEW COBR.VIEWMOVCUSTOMER;
-
End If;
-
-
CREATE view COBR.VIEWMOVCUSTOMER (CustCod, PolCod, MonCod, RamCod, EmiTypeCod, EmiNro,
-
EmiDate, MovTypeCod, MovPolNro) AS
-
-
SELECT CUST.CustCod, POL.PolCod, POL.MonCod, POL.RamCod, MOV.EmiTypeCod, MOV.EmiNro,
-
MOV.EmiDate, MOV.MovTypeCod, MOV.MovPolNro
-
-
FROM COBR.CUSTOMER AS CUST JOIN COBR.POLICY AS POL ON CUST.CustomerCod = POL.CustomerCod
-
-
JOIN COBR.MOVEMENTS AS MOV ON
-
MOV.PolCod = POL.PolCod and
-
MOV.MonCod = POL.MonCod and
-
MOV.RamCod = POL.RamCod
-
-
WHERE MOV.MovTypeCod = 'PAY' and
-
MOV.MovPolDate> = StartDateMonitor and
-
MOV.MovPolDate <= FinishDateMonitor;
-
-
END P1
-
-
Can anyone help me?
10 6664
The correct header syntax for a DB2 stored procedure is - create procedure procName (IN paramName dataType)
@Rabbit
Hi Rabbit.
Thank you for your observation. I believe that DB2 accepts it both ways, and it was previously as you mention it. I changed it to see if this was not the problem and the results were the same. Apparently DB2 is not recognizing the SQL parameters as valid in the SQL sentence.
Thanks again for your response.
Well, if it's not the header, then it might be the > =. There should be a space after the field name and the greater than symbol. And I don't think there should be a space between the symbol and the equal sign.
Yes sir, you are right in your comment about the spaces, but I think that was introduced when I did the Copy & Paste becuase my original code I have it as they talk about it.
Let me tell you that the tests changed the parameters SQL for constant date: '2011-09-01 'and '2011-09-07' and thus does the SP is OK. The issue is that I need the SQL sentence is dynamic. In the IBM site I read about a setting "DYNAMICRULES" for dynamic SQL, however when is not clear to me as I set this up.
I have no idea what you just said. Can you please explain that second paragraph again?
Sorry... Online translation was not very good. I got someone to help me:
I ran some test, changing the SQL parameters for date constants ('2011-09-01 'and '2011-09-07'). In this case, the SP worked perfectly. However, I need the SQL sentence to be dynamic, using the SP parameters. In the IBM site I read about a setting "DYNAMICRULES" for dynamic SQL but I am not clear as to how to implement it.
At this point, I'm not sure what could be wrong. I'll see if any of the other experts have more experience in DB2 stored procedures.
Thanks Rabbit... I believe that the problem occurs with Dynamic SQL because now I ran changing the SQL parameters with variables SQL (defined with DECLARE) and occurs same error.
Tahnk you for your help. If you can find something, I'll be very grateful
Rabbit,
In the IBM Data Studio Forum Ruiming replied with the following:
Hi,
Currently the CREATE VIEW statement does not support parameters. You may refer to the CREATE VIEW statement section in DB2 LUW 9.7 manuals for more information. Here are some excerpt from the DB2 manual:
"Defines the view. At any time, the view consists of the rows that would result if the SELECT statement were executed. The fullselect must not reference host variables, parameter markers, or declared temporary tables. However, a parameterized view can be created as an SQL table function."
Ruiming
This explains why it failed with different options that I tried.
Thanks a lot for your help!!
Glad you found your answer, good luck with your project.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: MD |
last post by:
I am trying to create a dynamic SQL statement to create a view.
I have a stored procedure, which based on the parameters passed calls
different stored procedures. Each of this sub stored procedure...
|
by: Hugo Lefevre |
last post by:
Dear,
I have a problem : I have a database which contains my data of hardware. The
Id is a varchar and I want at my filling form that my user know which is the
last one. So I made a store...
|
by: Hrvoje Voda |
last post by:
I have this code:
SqlConnection conn = null;
string Table="";
int rCount;
conn = new
|
by: c676228 |
last post by:
Hi everyone,
I wrote a store procedure that fetch one row data in the database based on
the parameter value I entered. After I created the store procedure,
the store procedure code looks like...
|
by: c676228 |
last post by:
Hi everyone,
I am just wodering in asp program, if there is anybody writing store
procedure for inserting data into database since there are so many parameters
need to be passed into store...
|
by: JohnnyDeep |
last post by:
I am trying to create a store proc that contain a create index with
the cluster option and I receive
DB21034E The command was processed as an SQL statement because it was
not a
valid Command...
|
by: seep |
last post by:
salam to everyone..
as a new bee in .net i m finding lot of difficulty. i want to get all records of a table from database via store procedure.but spending many days i dont know how can i do...
|
by: kya2 |
last post by:
I am not able to create following store procedure.
CREATE PROCEDURE DBSAMBA.InsertDeleteBatch(OUT norows INT )
RESULT SETS 1
LANGUAGE SQL
BEGIN part1
DECLARE TOTAL_LEFT INT DEFAULT 0;
...
|
by: asifNewbie |
last post by:
I have created table like this...
CREATE TABLE INVOICEMASTER(INVOICEID INT IDENTITY(1,1),EXPORTER_REF INT,CONSIGNEE_REF INT,BUYER_REF INT,AGENT_REF INT,INVOICENO VARCHAR(20),INVOICEDATE...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
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...
|
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,...
|
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...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
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...
| |