February 9, 2006 at 4:04 pm
Hi Every Buddy,
I am facing a prob, I want to use user defined function as the default value in the table. the function name is dbo.UDF_GetServerName().
When i query the table it shows this as a string "dbo.UDF_GetServerName()" as a default value.
But at the same time when i use GetDate() as a default value, it works fine.
Please tell me how can i use my own function as a default valus.???
Thank you,
Noman
February 11, 2006 at 8:29 pm
Hi Noman,
Without seeing your DDL, I'd take a wild guess that you put your function name inside single quotes.
Here is a quick and dirty sample that seems to work...
create function dbo.udf_getServer()
returns varchar(128)
AS begin
return(convert(varchar(128), getdate()))
end
go
create table tester(pkInt int identity(1, 1) not null primary key,
datum varchar(128) not null constraint df_tester_datum default (dbo.udf_getServer()))
insert tester default values
insert tester default values
select * from tester
drop table tester
drop function udf_getServer
Viewing 2 posts - 1 through 1 (of 1 total)
You must be logged in to reply to this topic. Login to reply