Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Incrementing a field with a select statement
Message
De
15/08/2002 12:20:25
 
 
À
15/08/2002 11:14:12
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Syntaxe SQL
Divers
Thread ID:
00690012
Message ID:
00690041
Vues:
12
You can't directly do it with a SELECT statement but once you've got your new table, you can use the UPDATE statement to do what you want:

CREATE #X (c int)

INSERT INTO #x values (1)
INSERT INTO #x values (1)
INSERT INTO #x values (1)
INSERT INTO #x values (1)
INSERT INTO #x values (1)

select * from #x

DECLARE @z int
SET @z=16
UPDATE #x set @z=@z+1, c=@z

SELECT * FROM #x

-Mike

>Hello Group,
>
>Can I increment a field in a select statement.
>
>I have a table with two hundred rows I want to update add my field with values from 300 - 500
>I have a variable name @newvalue
>
>can I write a select statement that will create a new table I.E.
>
>SELECT @NewValue (some increment method) as myuniquefield, name, address
>INTO myNewTable
>FROM myOldTable
>
>Thanks
>Jim
Michael Levy
MCSD, MCDBA
ma_levy@hotmail.com
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform