0

in MS-SQL I can do something like this

@myVar AS int;
@myVar = 12;

SELECT * FROM table WHERE field = @myVar;

this totally bombs out in DB2 - and I'm not sure if it's RDBMS specific or if it's because I've FUBAR'd the syntax...

Any help is appreciated

j-p
  • 3,698
  • 9
  • 50
  • 93

2 Answers2

0

there are a limited number of things you can do dynamically in db2 sql compared to ms-sql. most of the syntax for what you appear to be attempting is reserved for use only in a procedure in db2. see the documentation here http://publib.boulder.ibm.com/infocenter/db2luw/v9r5/topic/com.ibm.db2.luw.sql.ref.doc/doc/r0004240.html for what you can do dynamically in db2.

if you are ok supplying parameter value on the fly just use select * from table where field = ?; when you run it, it will ask you to supply a value for the parm.

MrG
  • 1,525
  • 13
  • 24
  • not on the fly - but maybe I'll try that - I just have a series of queries I want to execute, that use similar filter data - I figured if I typed it once at the top - I would have to 'retype' it over and over when I want to reuse that script. article was unhelpful - but I appreciate the help. – j-p Oct 17 '11 at 16:23
0

If you are using ADO.NET Data Provider to connect to the DB2 Express-C, you can prefix bound SQL parameters with @.

I'm not sure about other DB2 environments, but common symbols used in other databases are: : and ?, so it might be worth trying one of those.

Branko Dimitrijevic
  • 50,809
  • 10
  • 93
  • 167
  • interesting - I'm using the com.ibm.db2.jcc.DB2Driver (db2jcc.jar) to connect thru DBeaver client. maybe I'll try IBM Control Center (that'll take forever!).. : didn't seem to help. thx – j-p Oct 17 '11 at 16:28