Solved

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

Posted on 2009-07-16
5
3,219 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
  • 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

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

I annotated my article on ransomware somewhat extensively, but I keep adding new references and wanted to put a link to the reference library.  Despite all the reference tools I have on hand, it was not easy to find a way to do this easily. I finall…
Entering a date in Microsoft Access can be tricky. A typo can cause month and day to be shuffled, entering the day only causes an error, as does entering, say, day 31 in June. This article shows how an inputmask supported by code can help the user a…
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.

759 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now