Fetching the list of last values from SQL Server database and left join to a view -


Is there a way to get a list of last values ​​from the database? I have session list column StudId ( SID ), doctor ID ( TID code) >), date

I have a total of 5 children, who have SID 1,2,3,4,5 and 10 doctor TID 1 Together, 2,3 ...

Now all children are appointed for a specific doctor.

So child 1 has been given the doctor 10, 2 to doctor 5 and with this, a date when he starts teaching them. I can change a doctor from a fixed date for a child, for example, with the child 1 in the doctor Jane and FEB, and now he has been reassigned to the doctor from March 7. So I have a list of all these records. So a child can have several records in the table and the final record for that child will be the current doctor for that child.

How to get a list of previous records for all children from the table If I have 12 records in my DB then my query will only get 5 records that represent the child's final entry in the database. .

I used to use the last keyword to get tired on the same table, it was not working.

Is there any way that I can use an internal and left join to resolve this issue?

If you are on SQL Server 2005 and newer (you are not quite specific in that regard) one way CTE (Common Table Expression).

With this CTE, you can divide your statistics with some criteria - that is, your customer ID - and the SQL Server number all your "lines" For starting from 1, some criteria sorted by.

Then try to do something like this:

  See vs. vw_Current as the doctor in the form of current (select SID, TID, [Date] Line number = ROW_NUMBER () by the date of date of the CID by DESC) from dbo.SessionList) Select SID, TID, [date] CurrentTherapist from where ronam = 1   

Here, I I am selecting the "first" entry only for each "partition" (i.e. each SID - for each child) - of date Accordingly it is ordered.

Using this column name like piece: date is very bad - first of all, it does not tell me at all

Strong> What type of date is this - and besides, as a SQL Server 2008, DATE is a reserved keyword (for data type). Try to make your column name more expressive , avoid more meaningful and all SQL Server reserved keywords! (See)

I think it was suggested to use something like Session date (if it means the date of the date of the session), or ValidFrom If it represents the date on which a child / physician is actually valid / place on Milan.

Comments

Popular posts from this blog

php - PDO bindParam() fatal error -

logging - How can I log both the Request.InputStream and Response.OutputStream traffic in my ASP.NET MVC3 Application for specific Actions? -

java - Why my included JSP file won't get processed correctly? -