Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Check whether field exists or stored proc exists
Message
Information générale
Forum:
Visual FoxPro
Catégorie:
Base de données, Tables, Vues, Index et syntaxe SQL
Versions des environnements
Visual FoxPro:
VFP 9 SP2
OS:
Windows XP SP2
Network:
Windows 2003 Server
Database:
MS SQL Server
Application:
Desktop
Divers
Thread ID:
01479178
Message ID:
01479190
Vues:
50
>>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
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform