Author |
Topic |
skiski
Starting Member
15 Posts |
Posted - 2010-04-25 : 03:34:42
|
I need two query show in one query Help me pleaseSELECT SUM(d1.bed-d1.bes) AS oldAmount FROM tblDaftar d1 WHERE d1.iyear= 1389 AND d1.dat < 13890205SELECT d3.dat,d3.des,d3.bed,d3.bes, Amount=(SELECT SUM(d2.bed-d2.bes) FROM tblDaftar d2 WHERE d2.id<=d3.id), oldAmount=0FROM tblDaftar d3 WHERE d3.iyear= 1389 AND d3.dat BETWEEN 13890205 AND 13890205 Order By d3.ID |
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2010-04-25 : 03:37:00
|
this ?SELECT d3.dat,d3.des,d3.bed,d3.bes,Amount=(SELECT SUM(d2.bed-d2.bes) FROM tblDaftar d2 WHERE d2.id<=d3.id),oldAmount=(SELECT SUM(d1.bed-d1.bes) AS oldAmount FROM tblDaftar d1 WHERE d1.iyear= 1389 AND d1.dat < 13890205)FROM tblDaftar d3WHERE d3.iyear= 1389AND d3.dat BETWEEN 13890205 AND 13890205Order By d3.ID KH[spoiler]Time is always against us[/spoiler] |
|
|
skiski
Starting Member
15 Posts |
Posted - 2010-04-25 : 03:44:39
|
if tblDaftar eof=true and bof=true and oldAmount eof=false and bof=false thennot result oldAmount |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2010-04-25 : 04:09:21
|
quote: Originally posted by skiski if tblDaftar eof=true and bof=true and oldAmount eof=false and bof=false thennot result oldAmount
Don't quite understand what are you trying to achieve here.Please post your table DDL, sample data and required result KH[spoiler]Time is always against us[/spoiler] |
|
|
skiski
Starting Member
15 Posts |
Posted - 2010-04-25 : 04:59:50
|
CREATE TABLE [dbo].[tblDaftar] ( [ID] [int] IDENTITY (1, 1) NOT NULL , [SN] [int] NULL , [iMode] [int] NULL , [Dat] [int] NULL , [Des] [nvarchar] (300) COLLATE Arabic_CI_AS NULL , [bed] [float] NULL , [bes] [float] NULL , [vCheck] [nvarchar] (50) COLLATE Arabic_CI_AS NULL , [iYear] [int] NULL , [iCo] [int] NULL , [NumberCheck] [nvarchar] (10) COLLATE Arabic_CI_AS NULL ) ON [PRIMARY]GOINSERT INTO tblDaftar(SN,iMode,Dat,[Des],bed,bes,vCheck,iYear,iCo,NumberCheck)VALUES(3,2,13890203,'a',0,100000,0,1389,1000,0)INSERT INTO tblDaftar(SN,iMode,Dat,[Des],bed,bes,vCheck,iYear,iCo,NumberCheck)VALUES(4,2,13890204,'b',100000,0,0,1389,1000,0)INSERT INTO tblDaftar(SN,iMode,Dat,[Des],bed,bes,vCheck,iYear,iCo,NumberCheck)VALUES(5,2,13890204,'c',100000,0,0,1389,1000,0)INSERT INTO tblDaftar(SN,iMode,Dat,[Des],bed,bes,vCheck,iYear,iCo,NumberCheck)VALUES(8,2,13890204,'d',1000000,0,0,1389,1000,0)INSERT INTO tblDaftar(SN,iMode,Dat,[Des],bed,bes,vCheck,iYear,iCo,NumberCheck)VALUES(7,2,13890204,'e',0,300000,0,1389,1000,0)INSERT INTO tblDaftar(SN,iMode,Dat,[Des],bed,bes,vCheck,iYear,iCo,NumberCheck)VALUES(1,2,13890203,'f',100000,0,0,1389,1000,0)INSERT INTO tblDaftar(SN,iMode,Dat,[Des],bed,bes,vCheck,iYear,iCo,NumberCheck)VALUES(1,1,13890203,'g',0,100000,0,1389,1000,1)INSERT INTO tblDaftar(SN,iMode,Dat,[Des],bed,bes,vCheck,iYear,iCo,NumberCheck)VALUES(2,2,13890203,'h',200000,0,0,1389,1000,0) |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2010-04-25 : 05:06:34
|
whats the output you want out of this?------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2010-04-25 : 05:07:41
|
and the required result ? KH[spoiler]Time is always against us[/spoiler] |
|
|
skiski
Starting Member
15 Posts |
Posted - 2010-04-25 : 05:12:37
|
Thanks,Please execute this :1=SELECT SUM(d1.bed-d1.bes) AS oldAmount FROM tblDaftar d1 WHERE d1.iyear= 1389 AND d1.dat < 138902052=SELECT d3.dat,d3.des,d3.bed,d3.bes,Amount=(SELECT SUM(d2.bed-d2.bes) FROM tblDaftar d2 WHERE d2.id<=d3.id),oldAmount=(SELECT SUM(d1.bed-d1.bes) AS oldAmount FROM tblDaftar d1 WHERE d1.iyear= 1389 AND d1.dat < 13890205)FROM tblDaftar d3WHERE d3.iyear= 1389AND d3.dat BETWEEN 13890205 AND 13890205Order By d3.IDResult amount :1=1000000.02=NULLplease help me .... |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2010-04-25 : 13:03:02
|
what's that you are expecting as output? plzz post that------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
|
|
|
|