How to get the value of ID columns from older tables?

J

JB

Hello Community

I have several SQL Server tables with ID columns (the property of the
columns specify that it "Is Identity Yes").

The tables have many rows but I only want the value of the ID column
from a table when the where clause is satisfied.

These are "not" newly inserted in fact these rows can be very old and deep
within the table.

Can anyone tell me how I can extract the value from an Identity column from
a table?

Thanks
Jeff
 
M

Mr. Arnold

JB said:
Hello Community

I have several SQL Server tables with ID columns (the property of the
columns specify that it "Is Identity Yes").

The tables have many rows but I only want the value of the ID column
from a table when the where clause is satisfied.

These are "not" newly inserted in fact these rows can be very old and deep
within the table.

Can anyone tell me how I can extract the value from an Identity column from
a table?

Thanks
Jeff

You use T-SQL Select statement to select the row like anything else
selected from the table row.

If ID is an Identity field on a table, then it is this.

select ID from table where somefield = parm.

You would only get the resultset back of ID only.

You can then read the resultset using a datareader to access ID in the
resultset.
 
J

JB

Thank you Mr Arnold

I also saw that there is a keyword named IDENTITYCOL which I can use in
the select statement to capture the IDENTITY.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,819
Latest member
masterdaster

Latest Threads

Top