Solved

What is the AS400 sql syntax for declaring variables in a query

Posted on 2009-07-16
5
3,552 Views
Last Modified: 2012-05-07
Can anyone help me convert the MS SQL Server 2005 statement below to AS400 syntax? I would like to use variables in an AS400 query but I am having trouble with the syntax.

Thanks!
David
declare @project as varchar(8);
declare @YEmonth as smallint;
 
set @project = '0127-001'
set @YEmonth = 12
 
SELECT	* 
FROM	entity
WHERE	entity_id = @project and
	fiscalYEM = @YEmonth

Open in new window

0
Comment
Question by:dking_wri
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 18

Accepted Solution

by:
Dave Ford earned 500 total points
ID: 24870208

Unfortunately, all DB2's interacitve SQL environments (that I'm aware of) do not allow creating variables.

If you wrap those statements into a stored procedure, your script should work.

HTH,
DaveSlash

0
 
LVL 18

Expert Comment

by:Dave Ford
ID: 24870235

> If you wrap those statements into a stored procedure, your script should work.

Although I would lose the silly '@' - signs. That's Microsoft-specific syntax.
0
 

Author Comment

by:dking_wri
ID: 24870269
I want to use the variables in a script in a command box in Crystal Reports. I don't have the rights to create stored procedures on the AS400. Can you think of a way to make this work in Crystal?
0
 
LVL 18

Expert Comment

by:Dave Ford
ID: 24870384

I usually just create a stored procedure to be called from Crystal. I don't know any other way, but I am not a Crystal expert, so I could definitely be wrong.

You may want to cross-post this to the Crystal Reports topic area.

HTH,
DaveSlash
0
 

Author Closing Comment

by:dking_wri
ID: 31604268
Thanks for your help!
0

Featured Post

Webinar: MariaDB® Server 10.2: The Complete Guide

Join Percona’s Chief Evangelist, Colin Charles as he presents MariaDB Server 10.2: The Complete Guide on Tuesday, June 27, 2017 at 7:00 am PDT / 10:00 am EDT (UTC-7).

Question has a verified solution.

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

As technology users and professionals, we’re always learning. Our universal interest in advancing our knowledge of the trade is unmatched by most industries. It’s a curiosity that makes sense, given the climate of change. Within that, there lies a…
This article shows the steps required to install WordPress on Azure. Web Apps, Mobile Apps, API Apps, or Functions, in Azure all these run in an App Service plan. WordPress is no exception and requires an App Service Plan and Database to install
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.

691 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