473,386 Members | 1,708 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,386 software developers and data experts.

DB2 Store Procedure with Parameters in Create View

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:

Expand|Select|Wrap|Line Numbers
  1. CREATE PROCEDURE SP_CreateViewMovCustomer (StartDateMonitor IN DATE,
  2. FinishDateMonitor IN DATE)
  3.  
  4. SPECIFIC SP_CreateViewMovCustomer
  5.  
  6. P1: BEGIN
  7.  
  8. If Exists (Select 1 From SYSIBM.SYSVIEWS Where Name = 'VIEWMOVCUSTOMER' and creator = 'Cobra')
  9. Then
  10. DROP VIEW COBR.VIEWMOVCUSTOMER;
  11. End If;
  12.  
  13. CREATE view COBR.VIEWMOVCUSTOMER (CustCod, PolCod, MonCod, RamCod, EmiTypeCod, EmiNro,
  14. EmiDate, MovTypeCod, MovPolNro) AS
  15.  
  16. SELECT CUST.CustCod, POL.PolCod, POL.MonCod, POL.RamCod, MOV.EmiTypeCod, MOV.EmiNro,
  17. MOV.EmiDate, MOV.MovTypeCod, MOV.MovPolNro
  18.  
  19. FROM COBR.CUSTOMER AS CUST JOIN COBR.POLICY AS POL ON  CUST.CustomerCod = POL.CustomerCod
  20.  
  21. JOIN COBR.MOVEMENTS AS MOV ON  
  22. MOV.PolCod = POL.PolCod and
  23. MOV.MonCod = POL.MonCod and 
  24. MOV.RamCod = POL.RamCod
  25.  
  26. WHERE MOV.MovTypeCod = 'PAY' and
  27. MOV.MovPolDate> = StartDateMonitor and
  28. MOV.MovPolDate <= FinishDateMonitor;
  29.  
  30. END P1
  31.  
  32.  
Can anyone help me?
Oct 7 '11 #1
10 6664
Rabbit
12,516 Expert Mod 8TB
The correct header syntax for a DB2 stored procedure is
Expand|Select|Wrap|Line Numbers
  1. create procedure procName (IN paramName dataType)
Oct 7 '11 #2
@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.
Oct 8 '11 #3
Rabbit
12,516 Expert Mod 8TB
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.
Oct 8 '11 #4
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.
Oct 8 '11 #5
Rabbit
12,516 Expert Mod 8TB
I have no idea what you just said. Can you please explain that second paragraph again?
Oct 9 '11 #6
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.
Oct 9 '11 #7
Rabbit
12,516 Expert Mod 8TB
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.
Oct 9 '11 #8
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
Oct 10 '11 #9
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!!
Oct 11 '11 #10
Rabbit
12,516 Expert Mod 8TB
Glad you found your answer, good luck with your project.
Oct 11 '11 #11

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

Similar topics

4
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...
1
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...
3
by: Hrvoje Voda | last post by:
I have this code: SqlConnection conn = null; string Table=""; int rCount; conn = new
6
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...
11
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...
4
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...
0
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...
2
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; ...
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...
0
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,...
0
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$) { } ...
0
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...
0
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
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,...
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
Oralloy
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,...
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...

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.