Click here to Skip to main content
15,867,308 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
hii all

i am facing a problem with my sql stored procedure.. i m storing data in temp table after flteration. the OR condition is not working.. data is fatched accrding to condition on block.

help me..give me suggestion.. why my condition is not working
thanks in advance
my sp code is:
SQL
  USE [SCJ]
GO
/****** Object:  StoredProcedure [dbo].[spschlyes/noREPORT]    Script Date: 04/09/2014 04:57:52 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

ALTER PROCEDURE [dbo].[spschlyes/noREPORT] 
	-- Add the parameters for the stored procedure here
	 @DISTID VARCHAR(250),
    @BLOCKcount int 
AS
BEGIN	
	SET NOCOUNT ON;
	DECLARE
	@ChildTblName AS VARCHAR (125), 
   
     @vQuery1 AS VARCHAR (max) 
    
    SET @ChildTblName = '[' + @DISTID + 'Child_D' + ']'   
    CREATE TABLE #tblschyes_noreoprt
    (
        
        blockname  nvarchar(30),
        sch_yes   nvarchar(20), 
        sch_no   nvarchar(10) ,
        total    nvarchar(10)     
    );    
    DECLARE @N varchar
    SET @N = 1
    WHILE (@N <= @BLOCKcount+1)
    BEGIN
    SET @vQuery1='SELECT blockname, sch_yes, sch_no,(sch_yes+sch_no) as total
   FROM  (SELECT blockname as blockname FROM BLOCK where distt='+ @DISTID +'AND block='+@N+' ) BLK
   CROSS JOIN (SELECT COUNT(*) as sch_yes FROM ' + @ChildTblName + ' where (sch_code<>'' or class<>'') AND block='+@N+' ) a
   CROSS JOIN (SELECT COUNT(*) as sch_no FROM ' + @ChildTblName + ' where (nereason<>'' or droupout<>'') AND block='+@N+' ) b'
  
   INSERT INTO #tblschyes_noreoprt
    
    exec(@vQuery1)
   SET @N = @N + 1
   END
    select * from  #tblschyes_noreoprt    
    drop table #tblschyes_noreoprt;  
END
exec [spschlyes/noREPORT] '17',6
Posted
Updated 9-Apr-14 2:00am
v2

1 solution

its really simple


select * into #temptbl(
select * from tbl..................
)xx
 
Share this answer
 
Comments
bindash 11-Apr-14 0:57am    
thanks for reply.. but i m fetching data from 2 tables.. please read my problem carefully
AndrewCharlz 11-Apr-14 2:33am    
ultimately if u have two tables with same columns then what ull have to do is
select * into #temptbl(
select * from tbl..................
)xx
once u create a table
all ull have to do is insert from second table
insert into #temptbl
select * from tbl_2

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