Sometimes the simplest things are the most difficult... I'm creating a
UDF as below, then executing it but all I get is that the object does not exist. I must be missing something very basic here...
CREATE function dbo.GetColumnLength(@.vcTableName varchar(50), @.vcColumnName varchar(50)) returns smallint
as
begin
declare @.intLength as smallint
select @.intLength=sysC.prec from syscolumns sysC, sysobjects sysO
where sysC.Id = sysO.Id AND sysO.xtype ='U' And
sysO.Name = @.vcTableName AND
sysC.Name = @.vcColumnName
return @.intLength
End
GO
select top 2 * from player, dbo.GetColumnLength('playerdetails','email')Odd. Can you see the UDF in Enterprise Manager?|||select top 2 * from player, dbo.GetColumnLength('playerdetails','email')
Check the above statement.
I think it should be ...
select top 2 *,dbo.GetColumnLength('playerdetails','email') from player
And yes it just working fine ...
Joydeep|||Odd.
Odd?
Didn't you just answer this interview question a short while ago?
It's not retuning a table so it can't be in the FROM clause, and in any event, what you're doing doesn't make much sense.
Just what is it you are trying to accomplish?|||What I meant was, "Odd" that I didn't notice he had the function in his WHERE clause... :)
Still odd that he would recieve an error stating that the object doesn't exist...
Maybe what he wants is this:
select top 2 *, dbo.GetColumnLength('playerdetails','email') from player|||Thanks... I know I was tired at work today, but this mistake was just too much ;-)|||The code I posted was just an example, it's not the final UDF. It was simply just the only UDF code I had at hand.
Just as a principle, I should be able to have a UDF call in the table list, shouldn't I ?|||Yes, if the UDF returns a table rather than a scalar result.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment