![]() | |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
i want to make a FN that can check record exist or not. this is my FN: CREATE FUNCTION ufnCheckExists( ... 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. |
#3
| |||
| |||
|
|
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 |
#4
| |||
| |||
|
|
. my purpose to create this, is i can reuse my function without creating ambiguous function. |

#5
| |||
| |||
|
|
Sql is fine for plodding thru mountains of data, that is what it was designed for. It is not for things that require agility and specificity, in other words it is a poor language for application development. |
![]() |
| Thread Tools | |
| Display Modes | |
| |