Solved

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

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

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
SQL Update trigger 5 18
SSIS with VPN COnnection 2 76
T-SQL:  Collapsing 9 25
error in my cursor 5 30
Many companies are looking to get out of the datacenter business and to services like Microsoft Azure to provide Infrastructure as a Service (IaaS) solutions for legacy client server workloads, rather than continuing to make capital investments in h…
These days, all we hear about hacktivists took down so and so websites and retrieved thousands of user’s data. One of the techniques to get unauthorized access to database is by performing SQL injection. This article is quite lengthy which gives bas…
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
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

773 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