To properly format that, please wrap your code in code tags. If you don't you could end up here Worst Nodes. There is a subset of HTML that monks are allowed to use. You can read about that here. Writeup Formatting Tips.
You'll need to quote the column "i.ItemR/E" to get it to work. Like blue_cowdawg suggests, this is a SQL problem not a Perl one. If you cut the SQL code out and run it in isql or whatever SQL environment you use, you'll see that the dB Server doesn't understand the SQL. It can be difficult for a new Perl programmer to determine where the error is. Is it in the dB or is it in Perl? Please look at my earlier post and click in the link "Before asking a database related question". gmax has an excellent writeup about this. It will probably be a big help.
Good luck and please go back and wrap your code in code tags.