Icon View Thread

The following is the text of the current message along with any replies.
Messages 1 to 5 of 5 total
Thread Field exists inside a table.
Tue, Dec 18 2012 9:43 AMPermanent Link

Abdulaziz Al-Jasser

Hi,

I am trying to write a stored procedure and need to check if a field exists inside a table.  Any idea how to do that?

Regards,
Abdulaziz Jasser
Tue, Dec 18 2012 10:07 AMPermanent Link

Abdulaziz Al-Jasser

SOLVEDSmile


SELECT "Name" FROM Information.TableColumns WHERE TableName = 'TB_Users'
Regards,
Abdulaziz Jasser
Tue, Dec 18 2012 10:07 AMPermanent Link

Raul

Team Elevate Team Elevate

You need to query system information tables for this : TableColumns in
this case
:http://www.elevatesoft.com/manual?action=viewtopic&id=edb2sql&topic=TableColumns_Table

Raul

On 12/18/2012 9:43 AM, Abdulaziz Jasser wrote:
> I am trying to write a stored procedure and need to check if a field exists inside a table.  Any idea how to do that?
>
> Regards,
> Abdulaziz Jasser
>
Tue, Dec 18 2012 10:25 AMPermanent Link

Roy Lambert

NLH Associates

Team Elevate Team Elevate

Abdulaziz

>I am trying to write a stored procedure and need to check if a field exists inside a table. Any idea how to do that?

Its fairly simple - this is from my app - testing for existence of a table so I know it works

PREPARE InfoStmt FROM 'SELECT * FROM Information.Tables WHERE Name=?';
OPEN InfoCursor USING TableName;

IF (ROWCOUNT(InfoCursor) > 0) THEN
 EXECUTE IMMEDIATE 'DROP TABLE "'+TableName+'"';
END IF;

Alter it to

DECLARE FieldExists BOOLEAN DEFAULT TRUE;

PREPARE InfoStmt FROM 'SELECT * FROM Information.TableColumns WHERE Table = ? AND Name=?';
OPEN InfoCursor USING TableName, ColumnName;

IF (ROWCOUNT(InfoCursor) > 0) THEN
SET  FieldExists = TRUE;
END IF;

should do the trick

Roy Lambert [Team Elevate]
Wed, Dec 19 2012 11:36 AMPermanent Link

Abdulaziz Al-Jasser

Raul,
Roy,

Many thanks.

Regards,
Abdulaziz Jasser
Image