Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Is there a equivalent to VFP macro sub, name expressions
Message
 
 
À
18/09/2001 12:57:53
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Syntaxe SQL
Divers
Thread ID:
00557966
Message ID:
00557988
Vues:
10
This message has been marked as the solution to the initial question of the thread.
You can use Dynamic Sql as shown below in bold (not tested).

>I'm trying to create a stored procedure that will increment all of my datetime values in a database. In my example below I simply attempt to increment all datetime values by 3 months. I'm having some difficulties understanding how to do this in SQL2000, as I'm primarily a VFP developer and am trying to make the adjustment. If I query my database and get a cursor listing all of my DATETIME fields in the database, I'm not sure how to write a simple update which will use the cursor results in an UPDATE command. Here's the meat of my SP so far:
>
>declare fieldlist cursor for
>	select table_name, column_name, data_type
>	from information_schema.columns
>	where DAta_Type = 'datetime'
>
>declare @table AS CHAR(15), @Column AS CHAR(20)
<b>DECLARE @SqlUpdate varchar(1000)</b>
>SET NOCOUNT ON
>
>OPEN fieldlist
>
>FETCH NEXT FROM FieldList
>	INTO @table, @Column
>
>WHILE (@@FETCH_STATUS = 0)
>	BEGIN
    <b>@SqlUpdate = 'UPDATE ' + @table + ' SET ' + 
             @Column + ' = Dateadd(Month,3,' + @column + ')'
    EXECUTE sp_executesql @SqlUpdate </b>

<b>--</b>		UPDATE @table SET @Column = Dateadd(Month,3,@Column)
>		FETCH NEXT FROM FieldList INTO @Table, @Column
>	END
>
>Notice the update command would simply use the results from @table and @column to update the proper fields. In VFP I could use a Macro substitution using the @table and @Column variables, however I'm not sure how to do that in SQL. Any ideas?
>
>Thanks in advance.

You can use parameters with sp_executesql. Take a look if you can use it to your advantage.
--sb--
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform