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.
| Author |
Topic |
|
sent_sara
Constraint Violating Yak Guru
377 Posts |
Posted - 2008-09-25 : 06:27:39
|
| Hi Friends can any one help how t assign newid() as default inputparameterCreate Procedure Test(@sno int,@id varchar(256)=how to assign id here)asbeginset nocount onselect @id as 'new_id'set nocount offend |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-09-25 : 06:30:56
|
| use NEWID() function or NEWSEQUENTIALID() function if you need sequential guids. |
 |
|
|
sent_sara
Constraint Violating Yak Guru
377 Posts |
Posted - 2008-09-25 : 06:35:17
|
Incorrect syntax near '('. error is thrown,while assigning newid() as default input parameterCreate Procedure Test(@sno int,@id varchar(256)=newid())asbeginset nocount onselect @id as 'new_id'set nocount offendquote: Originally posted by visakh16 use NEWID() function or NEWSEQUENTIALID() function if you need sequential guids.
|
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-09-25 : 06:42:12
|
quote: Originally posted by sent_sara Incorrect syntax near '('. error is thrown,while assigning newid() as default input parameterCreate Procedure Test(@sno int,@id varchar(256)=newid())asbeginset nocount onselect @id as 'new_id'set nocount offendquote: Originally posted by visakh16 use NEWID() function or NEWSEQUENTIALID() function if you need sequential guids.
try like thisCreate Procedure Test(@sno int,@id varchar(256)=NULL)asbeginset nocount onselect isnull(@id,NEWID()) as 'new_id'set nocount off |
 |
|
|
sent_sara
Constraint Violating Yak Guru
377 Posts |
Posted - 2008-09-25 : 06:46:34
|
no visakh16,Iam asking why we can't assign in inputparamter itself ???quote: Originally posted by visakh16
quote: Originally posted by sent_sara Incorrect syntax near '('. error is thrown,while assigning newid() as default input parameterCreate Procedure Test(@sno int,@id varchar(256)=newid())asbeginset nocount onselect @id as 'new_id'set nocount offendquote: Originally posted by visakh16 use NEWID() function or NEWSEQUENTIALID() function if you need sequential guids.
try like thisCreate Procedure Test(@sno int,@id varchar(256)=NULL)asbeginset nocount onselect isnull(@id,NEWID()) as 'new_id'set nocount off
|
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-09-25 : 06:50:09
|
quote: Originally posted by sent_sara no visakh16,Iam asking why we can't assign in inputparamter itself ???quote: Originally posted by visakh16
quote: Originally posted by sent_sara Incorrect syntax near '('. error is thrown,while assigning newid() as default input parameterCreate Procedure Test(@sno int,@id varchar(256)=newid())asbeginset nocount onselect @id as 'new_id'set nocount offendquote: Originally posted by visakh16 use NEWID() function or NEWSEQUENTIALID() function if you need sequential guids.
try like thisCreate Procedure Test(@sno int,@id varchar(256)=NULL)asbeginset nocount onselect isnull(@id,NEWID()) as 'new_id'set nocount off
it wont allow use of non deterministic functions as default value of parameters. |
 |
|
|
|
|
|
|
|