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
 General SQL Server Forums
 New to SQL Server Programming
 Case Statement help

Author  Topic 

masond
Constraint Violating Yak Guru

447 Posts

Posted - 2014-03-03 : 07:48:00
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

169 Posts

Posted - 2014-03-03 : 07:55:46
can u plz provide the sample data

Veera
Go to Top of Page

masond
Constraint Violating Yak Guru

447 Posts

Posted - 2014-03-03 : 08:02:01
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 - 2014-03-03 : 10:30:41
Any one got any solutions ?
Go to Top of Page

xhostx
Constraint Violating Yak Guru

277 Posts

Posted - 2014-03-03 : 12:14:55
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

52326 Posts

Posted - 2014-03-03 : 13:06:48
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
Master Smack Fu Yak Hacker

1054 Posts

Posted - 2014-03-03 : 14:01:29
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
   

- Advertisement -