On Apr 17, 7:34 am, Serge Rielau <srie...@ca.ibm.comwrote:
sri wrote:
My environment is DB2v9.1, Windows/AIX and I am trying to compile the
storedprocbelow and I am getting an error, "ERROR [42601] [IBM][DB2/
NT] SQL0104N An unexpected token "WITH" was found following "User_ID
= UsrID; ". Expected tokens may include: "SELECT". LINE
NUMBER=11. SQLSTATE=42601"
CREATE PROCEDURE TestProc(IN UsrID INT)
LANGUAGE SQL
SPECIFIC TestProc
DYNAMIC RESULT SETS 1
BEGIN
DECLARE UserID INT DEFAULT -1;
SELECT * FROM tab_user where User_ID = UsrID;
WITH TempView (clnt_id) AS
(SELECT clnt_id FROM clients)
SELECT CLNT_ID FROM TempView;
END
Do you have a Sybase/SQL Server background?
In the SQL Standard you cannot just write a query and it turns into a
result set. You need to DECLARE a cursor WITH RETURN and OPEN that cursor.
E.g.
BEGIN
DECLARE cur WITH RETURN TO CLIENT FOR
SELECT * FROM tab_user WHERE User_ID = Usr_ID;
OPEN cur;
END
--
Serge RielauDB2Solutions Development
IBM Toronto Lab- Hide quoted text -
- Show quoted text -
Thanks for your reply -- I just copied some snippets of the procedure
and hence this in complete code, I am sorry for that. This is exactly
what I am trying to acheive. I want to use Common Table Expressions in
stored procedure when I run the following statement
BEGIN
WITH TempView (clnt_id) AS
(SELECT clnt_id FROM clients)
SELECT CLNT_ID FROM TempView;
END
independently then it runs just fine but when I put the same into a
stored procedure then I get the following error message
ERROR [42601] [IBM][DB2/NT] SQL0104N An unexpected token "WITH" was
found following "1 BEGIN ". Expected tokens may include:
"SELECT". LINE NUMBER=9. SQLSTATE=42601
Thanks,
Sri