By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,265 Members | 1,343 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,265 IT Pros & Developers. It's quick & easy.

How to include variable in CURSOR SQL Filter clause?

P: n/a
After trying every way I could come up with I can't get a filter clause
to work with a passed variable ...
I have a cursor that pulls a filter string from a table (works OK),
then I want to use that filter in a second cursor, but can't get the
syntax ...

@bakfilter is equal to "MISV2_db_%.BAK" before I try to open and fetch
from the second cursor. Here is the cursor declaration:

DECLARE curFiles CURSOR FOR
SELECT FileName, FileDate
FROM DataFile
WHERE (((Active)=1) AND ((FileName) LIKE '@bak_filter'))
ORDER BY FileDate DESC

What do I need to do to get it to use the string contained in
@bak_filter?

Thanks in advance, Jim

Jul 23 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
On 10 Jan 2005 14:53:35 -0800, jfro wrote:
After trying every way I could come up with I can't get a filter clause
to work with a passed variable ...
I have a cursor that pulls a filter string from a table (works OK),
then I want to use that filter in a second cursor, but can't get the
syntax ...

@bakfilter is equal to "MISV2_db_%.BAK" before I try to open and fetch
from the second cursor. Here is the cursor declaration:

DECLARE curFiles CURSOR FOR
SELECT FileName, FileDate
FROM DataFile
WHERE (((Active)=1) AND ((FileName) LIKE '@bak_filter'))
ORDER BY FileDate DESC

What do I need to do to get it to use the string contained in
@bak_filter?


Hi Jim,

Remove the quotes: LIKE @bak_filter

However, I hope that you're aware that cursor-based processing is usually
not needed? Set-based solutions are almost always better. Of course, if
you need to perform an intrinsically row-based operation (like sending
mail or performing some OS command with xp_cmdshell), this doesn't apply.

Best, Hugo
--

(Remove _NO_ and _SPAM_ to get my e-mail address)
Jul 23 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.