Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Check whether field exists or stored proc exists
Message
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Environment versions
Visual FoxPro:
VFP 9 SP2
OS:
Windows XP SP2
Network:
Windows 2003 Server
Database:
MS SQL Server
Application:
Desktop
Miscellaneous
Thread ID:
01479178
Message ID:
01479190
Views:
49
>>HI all
>>
>>My app is VFP9 running against MSSQL2005
>>
>>May I know how I can check if a field or stored proc exist in my MSSQL database.
>>
>>Your advice is much appreciated
>>
>>Thanks & Best Regards
>
>
>--- Check if the field exists
>
>IF EXISTS(SELECT * FROM INFORMATION_SCHEMA.COLUMNS 
>                   WHERE Column_Name = 'NameOfTheField' 
>                     AND Table_Name = 'YourTable')
>   SELECT CAST(1 AS bit) AS Exists
>ELSE
>   SELECT CAST(0 AS bit) AS Exists
>
>
>
>
>--- Check if SP exists
>
>IF EXISTS(SELECT * FROM sysobjects
>                   WHERE Name = 'YourSPName' 
>                     AND xType = 'P'
>   SELECT CAST(1 AS bit) AS Exists
>ELSE
>   SELECT CAST(0 AS bit) AS Exists
>
Hi Boris,

You can simplify this to the one SQL call, e.g.
select cast(case when exists(select 1 from ...) then 1 else 0 end as bit) as FieldExists
If it's not broken, fix it until it is.


My Blog
Previous
Reply
Map
View

Click here to load this message in the networking platform