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 2008 Forums
 Transact-SQL (2008)
 combining 2 queries

Author  Topic 

aciccia
Starting Member

8 Posts

Posted - 2011-08-01 : 21:45:37
I'm trying to get the 2 queries to work together but i'm having no luck. Any suggestions?

Thank you,


select *



from Arr_ANALYTICS.dbo.detail d

Inner join Arr_analytics.dbo.detail di

on d.SD_KEY=di.SD_KEY

where d.SD_TRAN_CDE_CAT in ('31')

and d.SD_BEN_WIR_ACCT_IDENT not like ('%twr%')

and d.SD_TERM_NAME_LOC = di.SD_TERM_NAME_LOC

and d.md_tran_amt1 > 4999

and di.SD_Tran_cde_cat in ('31')

and di.SD_BEN_WIR_ACCT_IDENT not like ('%twr%')

and di.md_tran_amt1 > 4999

AND di.DD_DATE BETWEEN DATEADD(minute, -10, d.DD_DATE) AND DATEADD(second, -5, d.DD_DATE)


AND EXISTS (Select SD_DATEKEY from Arr_Analytics.dbo.Detail di1

WHERE di.SD_KEY = di1.SD_KEY

and di1.SD_TRAN_CDE_CAT in ('21')

and di1.md_tran_amt1 > 10000

AND di1.DD_DATE BETWEEN DATEADD(day, -3, di.DD_DATE) AND DATEADD(second, -5, di.DD_DATE))


This part would be the second part that I want to incorporate.



And EXISTS (SELECT di1.SD_KEY, di1.SD_DATEKEY

FROM Arr_Analytics.dbo.Detail di1

JOIN Arr_Analytics.dbo.Master m

ON di1.SD_KEY = m.SM_KEY

WHERE m.DM_ACCT_OPN_DAT between '06/01/2011' and '07/27/2011')

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-08-02 : 01:05:26
what happens when you're just adding AND condition to existing query?

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

Go to Top of Page

aciccia
Starting Member

8 Posts

Posted - 2011-08-02 : 01:24:36
It's just ignoring it
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-08-02 : 02:23:06
can you show some data sample and explain?

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

Go to Top of Page

aciccia
Starting Member

8 Posts

Posted - 2011-08-02 : 02:38:14
The first query is looking for 2 transactions within 10 minutes for >4999 when there has been a credit applied for >10000 3 days prior to the transactions

the second part is trying to look for recently created accounts.

i'm not quite sure what kind of data sample you need to get a better idea.
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-08-02 : 03:01:10
see

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


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

Go to Top of Page
   

- Advertisement -