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
 Regarding Stored Procedure

Author  Topic 

soori457
Yak Posting Veteran

85 Posts

Posted - 2008-02-21 : 03:04:40
create procedure Names_SP
(
@Testing varchar(30)
)
as
declare @var int
declare @name varchar(30)
set @var = len('@Testing')
while @var <= 0
begin
select @name = substring(@Testing, @var, 1) from Employee
create table @name( Letter varchar(30) )
set @var = @var-1
print @name
end

I'm getting error at @name in Create Table command

Can any one solve this, plzz

Thanks in Advance

Suresh 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 be
create procedure Names_SP
(
@Testing varchar(30)
)
as

declare @var int
declare @name varchar(30)
set @var = len('@Testing')
while @var <= 0
begin
select @name = substring(@Testing, @var, 1) from Employee
create table [name]( Letter varchar(30) )
set @var = @var-1
print @name

Again, I am not sure what what is your objective.Please consult any beginners SQL server book.
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2008-02-21 : 04:05:52
You should explain what you are trying to do
It seems you are trying to create tables dynamically?

Madhivanan

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

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 letters
How it is possible

Suresh Kumar
Go to Top of Page

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 letters
How it is possible

Suresh Kumar


Why do you need this?

Madhivanan

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

soori457
Yak Posting Veteran

85 Posts

Posted - 2008-02-21 : 05:24:54
If I pass Suresh
I have to create table with all names starting with S, U , R,E , S , H
EX:

S(Table Name) U R E S H

Suresh Upendra Rajesh Eswar Suresh Hari
Santosh Uma Ravi Santosh Haritha
Ramana Harika

like this

Suresh Kumar
Go to Top of Page

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)
)
as
declare @var int
declare @name varchar(30)
set @var = len('@Testing')
while @var <= 0
begin
select @name = substring(@Testing, @var, 1) from Employee
create table @name( Letter varchar(30) )
set @var = @var-1
print @name
end

I'm getting error at @name in Create Table command

Can any one solve this, plzz

Thanks in Advance

Suresh Kumar


Hi!
please try this
--------------
alter procedure Names_SP
(
@Testing varchar(30)
)
as
begin
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

end
end
exec Names_SP 'abc'



kiruthika
http://www.ictned.eu
Go to Top of Page

soori457
Yak Posting Veteran

85 Posts

Posted - 2008-02-21 : 07:57:45
Thanks for ur reply

If I pass 'abc', then table is create with the last letter only.

Exec Names_SP 'abc'

If I execute this command
There is already an object named 'c' in the database.

Suresh Kumar
Go to Top of Page

soori457
Yak Posting Veteran

85 Posts

Posted - 2008-02-21 : 08:13:33
Thanks kiruthika

am sorry, the code is working

Suresh Kumar
Go to Top of Page
   

- Advertisement -