SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Case Statement help
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

masond
Constraint Violating Yak Guru

447 Posts

Posted - 03/03/2014 :  07:48:00  Show Profile  Reply with Quote
Hey all i need some help

Aim –
Only find Fdmsaccountno
where Account_Status <> 16 on period_DT “2012-12-01 00:00:00” however Account_Status = 16 on “2012-11-01 00:00:00”

I use the following conversion on period_Dt CONVERT(VARCHAR(24),period_DT,120)
Looking forward to your help

Regards
D

VeeranjaneyuluAnnapureddy
Posting Yak Master

India
164 Posts

Posted - 03/03/2014 :  07:55:46  Show Profile  Reply with Quote
can u plz provide the sample data

Veera
Go to Top of Page

masond
Constraint Violating Yak Guru

447 Posts

Posted - 03/03/2014 :  08:02:01  Show Profile  Reply with Quote
Hi Veera

This would need to be included

FDMSAccountNo Account_Status Period_DT
295268 16 2012-11-01 00:00:00
295268 13 2012-12-01 00:00:00


This would need to be excluded.

FDMSAccountNo Account_Status Period_DT
295268 16 2012-11-01 00:00:00
295268 16 2012-12-01 00:00:00


FDMSAccountNo Account_Status Period_DT
295268 13 2012-11-01 00:00:00
295268 16 2012-12-01 00:00:00
Go to Top of Page

masond
Constraint Violating Yak Guru

447 Posts

Posted - 03/03/2014 :  10:30:41  Show Profile  Reply with Quote
Any one got any solutions ?
Go to Top of Page

xhostx
Constraint Violating Yak Guru

USA
277 Posts

Posted - 03/03/2014 :  12:14:55  Show Profile  Reply with Quote
please provide you SQL. and it looks like the results you trying to include/exclude match. So, be little explicite please.

--------------------------
Joins are what RDBMS's do for a living
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
52309 Posts

Posted - 03/03/2014 :  13:06:48  Show Profile  Reply with Quote
Not fully clear but from your sample data looks like this

SELECT
FROM table t
WHERE NOT EXISTS (SELECT 1
FROM table
WHERE FDMSAccountNo = t.FDMSAccountNo 
AND Period_DT ='20121201'
AND Account_Status = 16
)
AND EXISTS (SELECT 1
FROM table
WHERE FDMSAccountNo = t.FDMSAccountNo 
AND Period_DT ='20121101'
AND Account_Status = 16
)


------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page

MIK_2008
Flowing Fount of Yak Knowledge

Pakistan
1052 Posts

Posted - 03/03/2014 :  14:01:29  Show Profile  Reply with Quote
Or may be this?

SELECT Fdmsaccountno
FROM TableA
WHERE (Account_Status <> 16 AND period_DT = '2012-12-01 00:00:00')
OR (Account_Status = 16 AND period_DT = '2012-11-01 00:00:00')

However, the confusing part is the following record which you said to be included as well as excluded in your narrative...
295268 16 2012-11-01 00:00:00

Cheers
MIK
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.11 seconds. Powered By: Snitz Forums 2000