Fez Vrasta
Fez Vrasta

Reputation: 14835

MS SQL use IDENT_CURRENT as variable of query

I need to use the IDENT_CURRENT of a specific table inside a query I'm writing.

I don't want to do a query to store the ID and another query to use it. I'd like something like:

UPDATE my_table1
SET my_column1 = IDENT_CURRENT(my_table2)
WHERE my_column2 = ?

Is it possible?

Upvotes: 1

Views: 1823

Answers (2)

Sandr
Sandr

Reputation: 776

Yes, this code will work fine. Table name for the function IDENT_CURRENT must be in quotas:

UPDATE my_table1
SET my_column1 = IDENT_CURRENT('my_table2')
WHERE my_column2 = ?

Upvotes: 1

asantaballa
asantaballa

Reputation: 4048

Needs quotes around table name.

UPDATE my_table1
SET my_column1 = IDENT_CURRENT('my_table2')
WHERE my_column2 = ?

Upvotes: 0

Related Questions