Mr_Shaw
asked on
SQL error Invalid column name
I have the following stored procedure
CREATE PROCEDURE [GEN].[ColumnsList]
-- Add the parameters for the stored procedure here
(
@DatabaseName nvarchar(255),
@TableName nvarchar(255)
)
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
-- Insert statements for procedure here
exec ('Select COLUMN_NAME, DATA_TYPE from Ardentia_Healthware_5_Rele ase.INFORM ATION_SCHE MA.COLUMNS where TABLE_CATALOG ='+ @TableName)
END
Which when I execute using the following
EXEC @return_value = [GEN].[ColumnsList]
@DatabaseName = N'SSO',
@TableName = N'SSO_Config'
I get the following error
Msg 207, Level 16, State 1, Line 1
Invalid column name 'SSO_Config'.
(1 row(s) affected)
I am not sure how to overcome this error.
can anybody help?
I am using SQL 2005
CREATE PROCEDURE [GEN].[ColumnsList]
-- Add the parameters for the stored procedure here
(
@DatabaseName nvarchar(255),
@TableName nvarchar(255)
)
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
-- Insert statements for procedure here
exec ('Select COLUMN_NAME, DATA_TYPE from Ardentia_Healthware_5_Rele
END
Which when I execute using the following
EXEC @return_value = [GEN].[ColumnsList]
@DatabaseName = N'SSO',
@TableName = N'SSO_Config'
I get the following error
Msg 207, Level 16, State 1, Line 1
Invalid column name 'SSO_Config'.
(1 row(s) affected)
I am not sure how to overcome this error.
can anybody help?
I am using SQL 2005
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
The problem is that we are not sure of your desired usage of @DatabaseName, if it is truely the database then Brandon is right above. If you are thinking Database is a specific Schema within the Ardentia_Healthware_5_Rele ase database then try the code below.
CREATE PROCEDURE [GEN].[ColumnsList]
-- Add the parameters for the stored procedure here
(
@DatabaseName nvarchar(255),
@TableName nvarchar(255)
)
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
-- Insert statements for procedure here
Select COLUMN_NAME, DATA_TYPE from Ardentia_Healthware_5_Release.INFORMATION_SCHEMA.COLUMNS where TABLE_SCHEMA = @DatabaseName AND TABLE_CATALOG = @TableName
END
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
thanks
should n't it be TABLE_NAME = @TableName