Click here to Skip to main content
15,892,072 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
create or replace
SQL
PROCEDURE xyz_tbl_proc
as
BEGIN

 execute immediate '
            CREATE TABLE xyz
            (
             empname varchar(10)
             )';
             END;

i want to write a stored procedure in db2 to create table.
once i run this table is not getting created. please help.
Posted
Updated 21-Oct-13 1:39am
v3

1 solution

SQL
create proc NewTable @TabName nvarchar(20),@Flag bit,@SID int,@Name varchar(20)
as
begin
if @Flag=1
begin
IF (EXISTS (SELECT * FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = @TabName))
BEGIN
  print 'hi'
END
else
begin
    declare @str varchar(max)
    set @str='create table @TabName (Sid int,Name varchar(20))'
    select @str=replace(@str,'@TabName',@TabName)
    exec(@str)
    print 'Table not found'
END
end
end


I hope it's working well and helping to you........:-)
 
Share this answer
 
Comments
[no name] 22-Oct-13 0:21am    
in db2 this is not working Frown | :( i want code in db2 Frown | :( im getting error in line "if exists" and table is still not getting created :(
Chintan Desai1988 22-Oct-13 1:54am    
ok then let me check out and solve them...... :-)
[no name] 22-Oct-13 3:06am    
THANKS ALOT ALOT :-)

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