If I run this statement in Query Analyzer, it properly returns 1
for my testing table. But if I put the statement into a stored
procedure, the stored procedure returns NULL. What am I doing
wrong? I suspect it may be related to how I defined the parameters
for the stored procedure. Perhaps my definition of TableName and
ColumnName don't match what COLUMNPROPERTY and OBJECT_ID expect to
receive, but I don't know where to look for the function declarations
for those. Any pointers would be appreciated.
Select statement:
SELECT COLUMNPROPERTY(OBJECT_ID('Table1'), 'TestID', 'IsIdentity') AS
IsIdentity
Table definition:
CREATE TABLE [dbo].[Table1] (
[TestID] [numeric](18, 0) IDENTITY (1, 1) NOT NULL ,
[Description] [varchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL
) ON [PRIMARY]
Stored Procedure definition:
CREATE PROCEDURE spTest
(@TableName varchar,
@ColumnName varchar)
AS SELECT COLUMNPROPERTY(OBJECT_ID(@TableName), @ColumnName,
'IsIdentity') AS IsIdentity