Click here to Skip to main content
15,893,588 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hey,
I need how to create dynamically columns in sql server-2005

using Stored procedures.

I am passing a column Name in Front end.
Posted

1 solution

try that in the following way

SQL
Create Procedure DynamicTable
(
@Column1 varchar(100),
@Column2 varchar(100)
)
as
Declare @DynamicQuery varchar(200)
Set @DynamicQuery = 'create table Test1('+ @Column1+' int,'+@Column2+' varchar(200))'
exec (@DynamicQuery)
 
Share this answer
 
Comments
ARK Kambhampati 29-Jul-11 3:29am    
Hi It Executed successfully But Can't add the columns
Mahendra.p25 29-Jul-11 3:42am    
Execute Procedure Like
DynamicTable 'YourColumnName1','YourColumnName2'

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900