Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Ms-Sql2000....field check
Message
 
 
Information générale
Forum:
Visual FoxPro
Catégorie:
Base de données, Tables, Vues, Index et syntaxe SQL
Divers
Thread ID:
00661603
Message ID:
00661705
Vues:
31
You can use INFORMATION_SCHEMA COLUMNS view to check if column exists already. You cannot just "plug" a variable into any T-SQL command. You've to use dynamic SQL in this case. See EXECUTE command and sp_executesql SP in BOL for details.
-- ALTER TABLE mal ADD @depo money null
IF NOT EXISTS (SELECT * FROM INFORMATION_SCHEMA.COLUMNS
		WHERE table_name = 'mal' 
			And column_name = @depo)
BEGIN
	EXECUTE ( 'ALTER TABLE mal ADD ' + @depo + ' money NULL')
END
>At the Foxpro, it can controll with INDBC command which field be or not at a file.
>
>Like : (FoxPro)
>
>IF INDBC(_seek,"FIELD") = .F.
>ALTER TABLE mal ADD COLUMN ("d" + ALLTRIM(STR(mary))) i NULL
>ENDIF
>
>At the Ms-Sql2000 Stored procedure I did a sample as follow. And I had trouble :
>
>1- the row of "ALTER TABLE mal ADD @depo money null" it gives back syntax error for @depo
>2- How can I get(handle) a field be or not at a file.
>
>Note : I want to do this operations inside of the stored procedure.
>
>Thanks
>
>Sample code of SQL :
>USE foxsql
>DECLARE @depo nvarchar(9)
>DECLARE depo_hrk CURSOR FOR
>SELECT DISTINCT 'depo_' + cast(depo as nvarchar(4)) as depo FROM hrk ORDER BY depo
>OPEN depo_hrk
>FETCH NEXT FROM depo_hrk INTO @depo
>WHILE @@fetch_status = 0
>BEGIN
>ALTER TABLE mal ADD @depo money null
>FETCH NEXT FROM depo_hrk INTO @depo
>END
>
>CLOSE depo_hrk
>deallocate depo_hrk
--sb--
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform