Click here to Skip to main content
15,906,625 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
this is my procedure:
SQL
ALTER procedure [dbo].[recursive]
(
   @id int =null,
  @studentname varchar(20) =null  
)
As
BEGIN
with ProductSearch 
As
(           
  select * from student        
)
                             
select * from ProductSearch 

if(@studentname is not null and @id is null)
Begin
  select * from productsearch where studentname =@studentname
end
else if(@studentname is  null and @id is not null)
Begin
  select * from productsearch where id =@id
end
end


After executing it I get following error
(3 row(s) affected)
Msg 208, Level 16, State 1, Procedure recursive, Line 39
Invalid object name 'productsearch'.

(1 row(s) affected)
Posted
Updated 14-Dec-10 21:03pm
v3

Sql is case sensitive in this case, replace productsearch with ProductSearch .

Hope this helps,
Fredrik Bornander
 
Share this answer
 
Comments
balongi 14-Dec-10 8:37am    
Giving same error.
Fredrik Bornander 14-Dec-10 8:43am    
Did you replace both the typos.
Changing productsearch to ProductSearch works for me for the same procedure.
balongi 14-Dec-10 8:45am    
it compile successfully but giving error after execution. Yes i replaced it .
balongi 14-Dec-10 8:49am    
this is my latest procedure
ALTER procedure [dbo].[recursive]
(
@id int =null,
@studentname varchar(20) =null
)
As
BEGIN
with ProductSearch
As
(
select * from student
)

select * from ProductSearch


if(@studentname is not null and @id is null)
Begin
select * from ProductSearch where studentname =@studentname
end
else if(@studentname is null and @id is not null)
Begin
select * from ProductSearch where id =@id
end
end
Try this,
ALTER procedure [dbo].[recursive]
(
   @id int =null,
  @studentname varchar(20) =null  
)
As
BEGIN
if(@studentname is not null and @id is null)
Begin
  select * from productsearch where studentname =@studentname
end
else if(@studentname is  null and @id is not null)
Begin
  select * from productsearch where id =@id
end
end


Remove the below from your stored procedure.
SQL
with ProductSearch
As
(
  select * from student
)
select * from ProductSearch
 
Share this answer
 
v2
Comments
balongi 14-Dec-10 8:35am    
i am storing the result of student table in productsearch. the productsearch is not a table
Toniyo Jackson 14-Dec-10 8:37am    
Replace productsearch with ProductSearch
balongi 14-Dec-10 8:53am    
yes, i replace it but same error is display this is my latest procedure:
set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
go


ALTER procedure [dbo].[recursive]
(
@id int =null,
@studentname varchar(20) =null
)
As
BEGIN
with ProductSearch
As
(
select * from student
)

select * from ProductSearch


if(@studentname is not null and @id is null)
Begin
select * from ProductSearch where studentname =@studentname
end
else if(@studentname is null and @id is not null)
Begin
select * from ProductSearch where id =@id
end
end
Dalek Dave 15-Dec-10 3:44am    
Good answer.
Toniyo Jackson 15-Dec-10 4:19am    
Tnanks Dave.

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