| Author |
Topic |
|
soori457
Yak Posting Veteran
85 Posts |
Posted - 2008-02-21 : 03:04:40
|
| create procedure Names_SP( @Testing varchar(30))asdeclare @var intdeclare @name varchar(30)set @var = len('@Testing')while @var <= 0beginselect @name = substring(@Testing, @var, 1) from Employeecreate table @name( Letter varchar(30) )set @var = @var-1print @nameendI'm getting error at @name in Create Table commandCan any one solve this, plzzThanks in AdvanceSuresh Kumar |
|
|
sunil
Constraint Violating Yak Guru
282 Posts |
Posted - 2008-02-21 : 03:36:08
|
| I am not able to get what you are trying to achieve.your SP should becreate procedure Names_SP(@Testing varchar(30))asdeclare @var intdeclare @name varchar(30)set @var = len('@Testing')while @var <= 0begin select @name = substring(@Testing, @var, 1) from Employeecreate table [name]( Letter varchar(30) )set @var = @var-1print @nameAgain, I am not sure what what is your objective.Please consult any beginners SQL server book. |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2008-02-21 : 04:05:52
|
| You should explain what you are trying to doIt seems you are trying to create tables dynamically?MadhivananFailing to plan is Planning to fail |
 |
|
|
soori457
Yak Posting Veteran
85 Posts |
Posted - 2008-02-21 : 04:20:51
|
| My requirement is If I pass Suresh Then I should create Table name with S, U, R, E, S, H lettersHow it is possibleSuresh Kumar |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2008-02-21 : 04:48:11
|
quote: Originally posted by soori457 My requirement is If I pass Suresh Then I should create Table name with S, U, R, E, S, H lettersHow it is possibleSuresh Kumar
Why do you need this?MadhivananFailing to plan is Planning to fail |
 |
|
|
soori457
Yak Posting Veteran
85 Posts |
Posted - 2008-02-21 : 05:24:54
|
| If I pass SureshI have to create table with all names starting with S, U , R,E , S , HEX:S(Table Name) U R E S HSuresh Upendra Rajesh Eswar Suresh HariSantosh Uma Ravi Santosh Haritha Ramana Harikalike thisSuresh Kumar |
 |
|
|
kiruthika
Yak Posting Veteran
67 Posts |
Posted - 2008-02-21 : 07:01:27
|
quote: Originally posted by soori457 create procedure Names_SP( @Testing varchar(30))asdeclare @var intdeclare @name varchar(30)set @var = len('@Testing')while @var <= 0beginselect @name = substring(@Testing, @var, 1) from Employeecreate table @name( Letter varchar(30) )set @var = @var-1print @nameendI'm getting error at @name in Create Table commandCan any one solve this, plzzThanks in AdvanceSuresh Kumar
Hi!please try this--------------alter procedure Names_SP(@Testing varchar(30))asbegin declare @var int,@i int declare @name varchar(30) declare @res varchar(100) set @var = len(@Testing) set @i=1 while @var >= @i begin select @name = substring(@Testing, @i, 1) set @res= 'create table '+ @name +'( Letter varchar(30) )' exec (@res) set @i = @i+1 print @i endendexec Names_SP 'abc'kiruthikahttp://www.ictned.eu |
 |
|
|
soori457
Yak Posting Veteran
85 Posts |
Posted - 2008-02-21 : 07:57:45
|
| Thanks for ur replyIf I pass 'abc', then table is create with the last letter only.Exec Names_SP 'abc' If I execute this commandThere is already an object named 'c' in the database.Suresh Kumar |
 |
|
|
soori457
Yak Posting Veteran
85 Posts |
Posted - 2008-02-21 : 08:13:33
|
| Thanks kiruthikaam sorry, the code is workingSuresh Kumar |
 |
|
|
|