Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

LIKE statement in a macro

Status
Not open for further replies.

Rbar

Programmer
Jun 25, 2001
18
US

I'm having trouble getting the syntax for a like statemetn to use paremeters in a macro. I can't get the paremeters to work. Can anyone se what I'm missing?

replace macro MACRO_DB.CollStatsPT_M (DBname Char (50), indicator Char (12))
as
(
SELECT databasename, tablename
'FROM
DBC.Tables
WHERE
DatabaseName like any ('%:indicator%',':DBname')
ORDER By databasename, tablename;)
 
1. Indicator is a reserved word.

2. Don't quote the parameters, use
'%' || :indic || '%'

3. Don't know if it's documented anywhere, that you can't concatenate when using ANY/ALL, but
DatabaseName like any ('%' || :indic || '%',:DBname)
returns a 3707 Syntax error in 05.00.00.17

4. Even if there was no error, it wouldn't return the expected result set, because of differences between = 'xx' and like 'xx' regarding Chars and trailing blanks.
DBname Char(50) will not work but DBname Char(30) will.
So it's better to change it to an ORed condition:
replace macro CollStatsPT_M (DBname Char (50), indic Char (12))
as
(
SELECT databasename, tablename
FROM
DBC.Tables
WHERE
DatabaseName like '%' || :indic || '%'
OR DatabaseName = :DBname
ORDER By databasename, tablename;
);

5. You know what happens when indic is an empty string?

Dieter
 
This construct worked:
'%'||trim:)dbname1)||'%'
the like % % with a space in the parameter entry isn't very selective. :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top