🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: bit.databases.mssql-l
Article #177

Built in counter

#177
From: Jim
Date: Sun, 25 Nov 2001 18:07
30 lines
1668 bytes
Hi,

   I have been looking for a way to create an automatic counter in
order to increase a value within a select statement (don't want to
create a cursor and loop through)

   I am trying something like:

   SELECT getnextvalue() AS record_id, first_name, second_name FROM
names

   I know MSSQL supports for the function newid() - hence allowing
for:

   SELECT newid() AS record_id, first_name, second_name FROM names

   The problem is that newid() creates a UID and this I can not use. 
If MSSQL does not provide a built in function to obtain the next
available system id (as a counter), is there then a way to invoke a
stored procedure from the SELECT statement such as:

   SELECT sp_mycounter() AS record_id, first_name, second_name FROM
names

   or 

   SELECT (execute sp_mycounter()) AS record_id, first_name,
second_name FROM names

   Thank you.
Technical Details
Message-ID: <28311b05.0111251007.25407ee5@posting.google.com>
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!postnews1.google.com!not-for-mail

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f6611,b092f5479f2d487,start
X-Google-Attributes: gidf6611,public
X-Google-ArrivalTime: 2001-11-25 10:07:01 PST
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!postnews1.google.com!not-for-mail
From: shija03@hotmail.com (Jim)
Newsgroups: bit.databases.mssql-l
Subject: Built in counter
Date: 25 Nov 2001 10:07:00 -0800
Organization: http://groups.google.com/
Lines: 30
Message-ID: <28311b05.0111251007.25407ee5@posting.google.com>
NNTP-Posting-Host: 63.125.218.30
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 8bit
X-Trace: posting.google.com 1006711620 7862 127.0.0.1 (25 Nov 2001 18:07:00 GMT)
X-Complaints-To: groups-abuse@google.com
NNTP-Posting-Date: 25 Nov 2001 18:07:00 GMT