![]() | ![]() Products ![]() ![]() ![]() ![]() |
Home » Technical Support » ElevateDB Technical Support » Support Forums » ElevateDB SQL » View Thread |
Messages 1 to 5 of 5 total |
![]() |
Mon, Oct 11 2010 4:05 AM | Permanent Link |
Surjanto Kwe PT. Usahajaya Ficooprasional | Hi, I use David Cornelius's function and tweaked it a bit to run in 2.04, but it seems that the result is always false
Can someone tell me where did I go wrong ? Regards, Surjanto CREATE FUNCTION "TableExists" (IN "TableName" VARCHAR(40) COLLATE ANSI) BEGIN DECLARE TblCursor CURSOR FOR TblStmt; DECLARE TblName VARCHAR; PREPARE TblStmt FROM 'SELECT * FROM Information.Tables WHERE Name = ''+ TableName + '''; OPEN TblCursor; FETCH FIRST FROM TblCursor ('Name') INTO TblName; CLOSE TblCursor; UNPREPARE TblStmt; RETURN COALESCE(TblName, '''') = TableName; END |
Mon, Oct 11 2010 5:05 AM | Permanent Link |
Uli Becker | Surjanto,
> Hi, I use David Cornelius's function and tweaked it a bit to run in 2.04, but it seems that the result is always false > > Can someone tell me where did I go wrong ? The quotes seem to be wrong. Try this: PREPARE TblStmt FROM 'SELECT * FROM Information.Tables WHERE Name = ''' + Tablename + ''''; .... RETURN COALESCE(TblName, '') = TableName; Regards Uli |
Mon, Oct 11 2010 10:57 AM | Permanent Link |
David Cornelius Cornelius Concepts | Good catch, Uli. Yes, it needed some embedded quotes.
Glad someone is finding the script useful. ![]() -- David Cornelius Cornelius Concepts |
Tue, Oct 12 2010 2:24 AM | Permanent Link |
Surjanto Kwe PT. Usahajaya Ficooprasional | Thanks Uli and David,
I changed it a little bit to allow case insensitive ALTER FUNCTION "TableExists" (IN "TableName" VARCHAR(40) COLLATE ANSI_CI) RETURNS BOOLEAN BEGIN DECLARE TblCursor CURSOR FOR TblStmt; DECLARE TblName VARCHAR; PREPARE TblStmt FROM 'SELECT * FROM Information.Tables WHERE Name = '''+ TableName + ''''; OPEN TblCursor; FETCH FIRST FROM TblCursor ('Name') INTO TblName; CLOSE TblCursor; UNPREPARE TblStmt; RETURN COALESCE(UPPER(TblName1), '''') = UPPER(TableName); END |
Tue, Oct 12 2010 2:25 AM | Permanent Link |
Surjanto Kwe PT. Usahajaya Ficooprasional | Sorry the correct one should be
CREATE FUNCTION "TableExists" (IN "TableName" VARCHAR(40) COLLATE ANSI_CI) RETURNS BOOLEAN BEGIN DECLARE TblCursor CURSOR FOR TblStmt; DECLARE TblName VARCHAR; PREPARE TblStmt FROM 'SELECT * FROM Information.Tables WHERE Name = '''+ TableName + ''''; OPEN TblCursor; FETCH FIRST FROM TblCursor ('Name') INTO TblName; CLOSE TblCursor; UNPREPARE TblStmt; RETURN COALESCE(UPPER(TblName), '''') = UPPER(TableName); END |
This web page was last updated on Wednesday, August 14, 2024 at 03:12 PM | Privacy Policy![]() © 2024 Elevate Software, Inc. All Rights Reserved Questions or comments ? ![]() |