Tyler Kent
Tyler Kent

Reputation: 33

Select Identity without 'into"

Alright, I'm 99% sure it's possible... How do I select an identity column without using 'into' in SSMS 2008?

For example,

I know this doesn't work, but it's what I'm looking for...

Select  PK as Identity (int,1,1), A.*
From    Table_1 A

Upvotes: 3

Views: 6815

Answers (2)

TFN
TFN

Reputation: 1

I assume you want to create ID to data after getting whatever data using the SELECT. Where you may use within a UPDATE or a MERGE or some sort of DML.

SELECT row_number() over (order by newid()) AS ID, A.ColumnName
FROM (Select DISTINCT ColumnName From  Table_1)  A

Upvotes: 0

Andomar
Andomar

Reputation: 238078

If you're just looking for a random unique number, try:

Select  row_number() over (order by newid())
,       A.*
From    Table_1 A

Upvotes: 5

Related Questions