December 18, 2013 at 11:29 am
I am trying to write logic that says:
(( Status = 'P' --PENDING
AND TYPE = 'P' ) --PRIMARY
OR (STATUS = 'C' --CURRENT
AND TYPE = 'P' --PRIMARY
AND NOT EXISTS(STATUS = 'P'
AND STATUS = 'P')))
trying to make it work like use the pending one or use the current one if no pending one is available.
December 18, 2013 at 12:46 pm
cdl_9009 (12/18/2013)
I am trying to write logic that says:(( Status = 'P' --PENDING
AND TYPE = 'P' ) --PRIMARY
OR (STATUS = 'C' --CURRENT
AND TYPE = 'P' --PRIMARY
AND NOT EXISTS(STATUS = 'P'
AND STATUS = 'P')))
trying to make it work like use the pending one or use the current one if no pending one is available.
Your logic says exactly what you posted. Unfortunately I suspect that what you posted is not the logic you want. However, based on what you posted nobody can help you figure it out. At the very least give us the whole query and a description of the business rules you are trying to enforce.
You might want to take a look at the first article in my signature for best practices when posting questions.
_______________________________________________________________
Need help? Help us help you.
Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.
Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.
Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/
December 19, 2013 at 6:44 am
That logic was correct. SQL wasn't looking at my new SP that had that new logic so it was a mistake on my end. I had the wrong datebase up.
December 19, 2013 at 7:02 am
trying to make it work like use the pending one or use the current one if no pending one is available.
Let Me Assume like
Acronyms Used as below, your's is not Understand-able.
C = Current
PN = Pending
PR = Primary
Requirement:
-------------
If I am not wrong, then
Query Needs to meet the Either the Status with Pending and type with Primary OR Status with Current and Type with Primary
and you dont want to list out records which has both on pending Status !!
If my Understanding is correct below is your Query,
SELECT Column1,Column2,......
FROM dbo.[MyTable]
WHERE
(CASE
WHEN ([Status]='PN' AND [Type]='PR') THEN 1
WHEN ([Status]='C' AND [Type]='PR') THEN 1
WHEN ([Status]='PN' AND [Type]='PN') THEN 0
ELSE 0 --this is optional
END)=1
or let me know your requirement to helpout you exactly what you want.
Thanks,
Prabhu
Viewing 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply