Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Inserting and selecting at the same time
Message
De
23/09/2013 10:14:37
 
 
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Syntaxe SQL
Versions des environnements
SQL Server:
SQL Server 2008
Application:
Desktop
Divers
Thread ID:
01583879
Message ID:
01583881
Vues:
46
Why not just use an autoinc int field and let SQL Server handle it internally?

>I wonder if it is possible to insert a new row and select the result in the same command?
>I have a table that keeps track of incrementing ID numbers (auto inc) and like to get a new ID at the same time.
>I don't want to create a SP because it would be easier to maintain if I can keep it in the same statement, but like to run one statement only.
>
>This does not work:
>Select max(emID) From EmpId Where (Insert into empID (emKey) values (NewID()))
>
>It gives "Incorrect syntax near the keyword 'Insert'"
Craig Berntson
MCSD, Microsoft .Net MVP, Grape City Community Influencer
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform