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
 General SQL Server Forums
 New to SQL Server Programming
 Assigning new guid

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 inputparameter

Create Procedure Test(@sno int,@id varchar(256)=how to assign id here
)
as
begin
set nocount on

select @id as 'new_id'

set nocount off
end

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.
Go to Top of Page

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 parameter


Create Procedure Test(@sno int,@id varchar(256)=newid()
)
as
begin
set nocount on

select @id as 'new_id'

set nocount off
end
quote:
Originally posted by visakh16

use NEWID() function or NEWSEQUENTIALID() function if you need sequential guids.

Go to Top of Page

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 parameter


Create Procedure Test(@sno int,@id varchar(256)=newid()
)
as
begin
set nocount on

select @id as 'new_id'

set nocount off
end
quote:
Originally posted by visakh16

use NEWID() function or NEWSEQUENTIALID() function if you need sequential guids.





try like this

Create Procedure Test(@sno int,@id varchar(256)=NULL
)
as
begin
set nocount on

select isnull(@id,NEWID()) as 'new_id'

set nocount off
Go to Top of Page

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 parameter


Create Procedure Test(@sno int,@id varchar(256)=newid()
)
as
begin
set nocount on

select @id as 'new_id'

set nocount off
end
quote:
Originally posted by visakh16

use NEWID() function or NEWSEQUENTIALID() function if you need sequential guids.





try like this

Create Procedure Test(@sno int,@id varchar(256)=NULL
)
as
begin
set nocount on

select isnull(@id,NEWID()) as 'new_id'

set nocount off


Go to Top of Page

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 parameter


Create Procedure Test(@sno int,@id varchar(256)=newid()
)
as
begin
set nocount on

select @id as 'new_id'

set nocount off
end
quote:
Originally posted by visakh16

use NEWID() function or NEWSEQUENTIALID() function if you need sequential guids.





try like this

Create Procedure Test(@sno int,@id varchar(256)=NULL
)
as
begin
set nocount on

select isnull(@id,NEWID()) as 'new_id'

set nocount off





it wont allow use of non deterministic functions as default value of parameters.
Go to Top of Page
   

- Advertisement -