Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Procedure

Author  Topic 

jogin malathi
Posting Yak Master

117 Posts

Posted - 2007-06-27 : 05:36:59
Hi all
I want to create table in stored procedure
as follows
is this correct

CREATE PROCEDURE dbo.StoredProcedure5
@p1 varchar(50),
@p2 varchar(50),
@d1 varchar(50),
@d2 varchar(50)
AS
create table t1(@p1 @d1,@p2,@d2)



Thanks In Advance

Malathi Rao

nr
SQLTeam MVY

12543 Posts

Posted - 2007-06-27 : 05:39:37
No.
Have a look at dynamic sql.
It's a bad idea to attempt it.


==========================================
Cursors are useful if you don't know sql.
DTS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page

jogin malathi
Posting Yak Master

117 Posts

Posted - 2007-06-27 : 05:40:31
quote:
Originally posted by nr

No.
Have a look at dynamic sql.
It's a bad idea to attempt it.


==========================================
Cursors are useful if you don't know sql.
DTS can be used in a similar way.
Beer is not cold and it isn't fizzy.



sorry and thanx

Malathi Rao
Go to Top of Page

jogin malathi
Posting Yak Master

117 Posts

Posted - 2007-06-27 : 05:42:43
quote:
Originally posted by nr

No.
Have a look at dynamic sql.
It's a bad idea to attempt it.


==========================================
Cursors are useful if you don't know sql.
DTS can be used in a similar way.
Beer is not cold and it isn't fizzy.





Can u give one small example and help

Malathi Rao
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2007-06-27 : 06:37:02
Why do you want to create a table based on the column names passed to the procedure?
You will end up with too much dynamic sql
Explain what you are trying to do

Make sure you read this fully
www.sommarskog.se/dynamic_sql.html

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

nr
SQLTeam MVY

12543 Posts

Posted - 2007-06-27 : 07:19:56
CREATE PROCEDURE dbo.StoredProcedure5
@p1 varchar(50),
@p2 varchar(50),
@d1 varchar(50),
@d2 varchar(50)
AS
exec ('create table t1(' + @p1 + @d1 + ',' + @p2+ @d2+ ')')
go

depends on what is in the parameters.
It's still a bad idea.

==========================================
Cursors are useful if you don't know sql.
DTS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page
   

- Advertisement -