You are here: Dinamyc Function « MsSQL Server « IT news, forums, messages
Dinamyc Function

Posted by aCe on 08/20/07 10:27

Hi all,
i wanna ask about dinamyc Function (FN).
This is my table :
CREATE TABLE [dbo].[unit](
[unitid] [int] IDENTITY(1,1) NOT NULL,
[unitname] [varchar](20) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[description] [varchar](50) COLLATE SQL_Latin1_General_CP1_CI_AS NOT
NULL,
[date_created] [datetime] NULL,
[user_created] [int] NOT NULL,
[date_modified] [datetime] NULL,
[user_modified] [int] NOT NULL,
CONSTRAINT [PK_unit] PRIMARY KEY CLUSTERED
(
[unitid] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]

i want to make a FN that can check record exist or not.
this is my FN:
CREATE FUNCTION ufnCheckExists(
@table varchar(255),
@key varchar(255),
@id int
)
RETURNS int
AS
BEGIN
DECLARE @returnResult int
IF( @id < 1 )
BEGIN
SET @returnResult = 0
END
ELSE
BEGIN
SET @returnResult =
CASE
WHEN EXISTS(
SELECT * FROM @table WHERE @key = @id
)
THEN (1)
ELSE (0)
END
END

error msg :
Msg 1087, Level 15, State 2, Procedure ufnCheckExists, Line 25
Must declare the table variable "@table".

is it possible to create it. or any suggestion.
my purpose to create this, is i can reuse my function without creating
ambiguous function.

thx,
ace

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация