Solved

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

Posted on 2009-07-16
5
3,428 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:
daveslash 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:daveslash
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:daveslash
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

Space-Age Communications Transitions to DevOps

ViaSat, a global provider of satellite and wireless communications, securely connects businesses, governments, and organizations to the Internet. Learn how ViaSat’s Network Solutions Engineer, drove the transition from a traditional network support to a DevOps-centric model.

Question has a verified solution.

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

This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
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
Via a live example, show how to set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.

730 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