Click here to Skip to main content
15,881,172 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello,
I have a Insert statment using left joins the query works fine, but when i use it in storeprocedure , then the store procedure is not inserting any data into the table.
please help.
Posted
Comments
Sandeep Mewara 19-Jun-12 7:50am    
Until you don't share your SP, it would be difficult to comment. Also, share how you invoke SP.
rohit24c 19-Jun-12 7:56am    
Create Procedure test_Sp
As
Begin

insert into Test([col1],[col2])
select a.Name,b.sub
from IdTable b
join Nametable a ON b.no = a.no
where b.no like 'x_%'
end

the insert query works fine when executed but in sp it is not inserting 0 records.
Mario Majčica 19-Jun-12 8:02am    
Please share the full SP you wrote, with parameters, etc. otherwise is very hard to help you. And please edit the question, formatting correctly the code parts.

1 solution

Hi,

Please try this

Create Procedure test_Sp 
As 
Begin 
     insert into Test 
     select a.Name,b.sub from 
     IdTable b join Nametable a ON b.no = a.no 
     where b.no like 'x_%' end


Also i have create one sample for it like,


Create table #IdTable([No] varchar(10),Name varchar(20))
Insert into #IdTable values('11111','AA')
Insert into #IdTable values('22222','BB')
Insert into #IdTable values('33333','CC')
Insert into #IdTable values('44444','DD')
Insert into #IdTable values('55555','EE')
 

Create table #Nametable(ID bigint, [No] varchar(10),sub varchar(20))
Insert into #Nametable values(1,'11111','A1')
Insert into #Nametable values(2,'22222','B1')
Insert into #Nametable values(3,'11111','A2')
Insert into #Nametable values(4,'22222','B2')
Insert into #Nametable values(5,'33333','C1')

Create Table #Test (Name varchar(20),Sub varchar(20))

insert into #Test

select a.Name,
b.sub 
from #Nametable b join #IdTable a ON b.no = a.no where b.no like '1%' 


select * from #Test 
Drop table #IdTable
Drop table #Nametable
Drop table #Test 
 
Share this answer
 

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