WorknHardr
asked on
SQL SP Create Dynamic Columns Exec Add Column Error?
I keep getting this error while trying to run the code below. I don't have any null data...
"The definition for column 'varchar' must include a data type."
"The definition for column 'varchar' must include a data type."
Declare @Name varchar(30)
Fetch Next From @MyCursor
Into @Name
exec ('ALTER TABLE dbo.MyTableTest Add ' + @Name + ' varchar(30)')
Show us the entire T-SQL, including how @MyCursor is populated.
ASKER
Alter PROCEDURE SP_MyTableTest
AS
BEGIN
Declare @Code varchar(10)
Declare @Name varchar(30)
Declare @price decimal(18, 0)
SET NOCOUNT ON;
Declare @MyCursor cursor;
Set @MyCursor = Cursor For Select Code, Name, Price from tbl_Products
Open @MyCursor
While @@FETCH_STATUS = 0
Fetch Next From @MyCursor
Into @Code, @Name, @price
Begin
exec ('ALTER TABLE dbo.MyTableTest Add ' + @Name + ' varchar(30)')
End
Close @MyCursor
Deallocate @MyCursor
END
GO
ASKER CERTIFIED 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.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Cool, thanks for ALL your help...