Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Query on Active/Inactive history table


Query on Active/Inactive history table

Author
Message
Kaushal
Kaushal
Grasshopper
Grasshopper (12 reputation)Grasshopper (12 reputation)Grasshopper (12 reputation)Grasshopper (12 reputation)Grasshopper (12 reputation)Grasshopper (12 reputation)Grasshopper (12 reputation)Grasshopper (12 reputation)

Group: General Forum Members
Points: 12 Visits: 138
Assumption:
You have an Account_Master table (and may be some other table(s) you need for the report) as follows
account_id int,
account_name varchar(100),
..
etc..

And you want to run a query for the report where you pass a date value as an input parameter, I would do something like this:


SELECT T1.ACCOUNT_ID, T1.ACCOUNT_NAME, ....
, (CASE WHEN T2.ACTIVE = 1 THEN 'Active' ELSE 'Inactive' END) as ACCOUNT_STATUS
FROM Account_Master AS T1
LEFT OUTER JOIN
( SELECT ACCOUNT_ID, ACTIVE FROM
(SELECT account_id, active, status_date
, ROW_NUMBER() OVER(PARTITION BY account_id ORDER BY status_date DESC) AS ROWNUM
FROM account_DeactivationReactivationHistory ) AS T2
WHERE ROWNUM = 1
) AS T2
ON T1.ACCOUNT_ID = T2.ACCOUNT_ID




HTH



Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search