Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 Please Help Me

Author  Topic 

skiski
Starting Member

15 Posts

Posted - 2010-04-25 : 03:34:42
I need two query show in one query
Help me please

SELECT SUM(d1.bed-d1.bes) AS oldAmount FROM tblDaftar d1 WHERE d1.iyear= 1389 AND d1.dat < 13890205

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=0
FROM 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 d3
WHERE d3.iyear= 1389
AND d3.dat BETWEEN 13890205 AND 13890205
Order By d3.ID



KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

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 then

not result oldAmount
Go to Top of Page

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 then

not 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]

Go to Top of Page

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]
GO

INSERT 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)
Go to Top of Page

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 MVP
http://visakhm.blogspot.com/

Go to Top of Page

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]

Go to Top of Page

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 < 13890205

2=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 d3
WHERE d3.iyear= 1389
AND d3.dat BETWEEN 13890205 AND 13890205
Order By d3.ID

Result amount :
1=1000000.0
2=NULL

please help me ....
Go to Top of Page

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 MVP
http://visakhm.blogspot.com/

Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2010-04-25 : 13:04:50
see how to post a question

http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -