[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

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

Posted on 2009-07-16
5
Medium Priority
?
3,817 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 1500 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] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

Question has a verified solution.

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

Lotus Notes has been used since a very long time as an e-mail client and is very popular because of it's unmatched security. In this article we are going to learn about  RRV Bucket corruption and understand various methods to Fix "RRV Bucket Corrupt…
In this blog post, we’ll look at how using thread_statistics can cause high memory usage.
Using examples as well as descriptions, and references to Books Online, show the different Recovery Models available in SQL Server and explain, as well as show how full, differential and transaction log backups are performed
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.

649 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