Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 calling NewSequentialId() indirectly from a query

Author  Topic 

waleed_cs2000
Starting Member

14 Posts

Posted - 2009-07-07 : 02:15:06
hi
I have a table column with default value newsequentialid() , but I need to get the new GUID generated value first before inserting new records.but calling it from a sql query issues that error:
quote:
"The newsequentialid() built-in function can only be used in a DEFAULT expression for a column of type 'uniqueidentifier' in a CREATE TABLE or ALTER TABLE statement. It cannot be combined with other operators to form a complex scalar expression."


I read that NewID(), and identity() can be called from sql queries but I NewID is slower in performance , and identity misses some GUID feature -as I guess.I also can't use "default" keyword before insertion statement.
so,is there any way to call newSequentialId() directly or indirectly?

thanks all

waterduck
Aged Yak Warrior

982 Posts

Posted - 2009-07-07 : 02:24:33
http://www.sqlteam.com/article/custom-auto-generated-sequences-with-sql-server
adopted from jeff

AMITOFO+AMEN+YA ALLAH Hope the query works
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-07-08 : 12:48:00
quote:
Originally posted by waleed_cs2000

hi
I have a table column with default value newsequentialid() , but I need to get the new GUID generated value first before inserting new records.but calling it from a sql query issues that error:
quote:
"The newsequentialid() built-in function can only be used in a DEFAULT expression for a column of type 'uniqueidentifier' in a CREATE TABLE or ALTER TABLE statement. It cannot be combined with other operators to form a complex scalar expression."


I read that NewID(), and identity() can be called from sql queries but I NewID is slower in performance , and identity misses some GUID feature -as I guess.I also can't use "default" keyword before insertion statement.
so,is there any way to call newSequentialId() directly or indirectly?

thanks all


whats the datatype of column for which newsequentialid() is default?
Go to Top of Page

waleed_cs2000
Starting Member

14 Posts

Posted - 2009-07-08 : 18:36:50
uniqueIdentifier data type
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-07-09 : 10:32:41
ok...so when did you get above error?when trying to insert an explicit guid value?
Go to Top of Page
   

- Advertisement -