如何使用多个select语句在临时表中存储数据 [英] how to store data in temp table using multiple select statement
本文介绍了如何使用多个select语句在临时表中存储数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
hii all
我面临着我的sql存储过程的问题..我在flteration后将数据存储在临时表中。 OR条件不起作用..数据因块状态而变胖。
帮我...给我建议..为什么我的病情不起作用
提前感谢
我的sp代码是:
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:
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
推荐答案
非常简单
select * into #temptbl(
select * from tbl ..................
)xx
its really simple
select * into #temptbl(
select * from tbl..................
)xx
这篇关于如何使用多个select语句在临时表中存储数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文