I have a ms sql server view, where i have a column Number and EventType and EventDT.…
- User
I have a ms sql server view, where i have a column Number and EventType and EventDT. Number is like id of object, EventType is name of Event and EventDT is datetime of event that happen with particular Number. I want to hide from View a row where EventType of particular Number which equals A and with order by EventDT going after EventType which equals B
- Assistant
To achieve this in your SQL Server view, you can use a Common Table Expression (CTE) or a subquery to help filter out the rows that meet your criteria. The general approach would be to find
Numbers that have an event of typeAthat occurs after an event of typeB, and then filter out those specific rows.Here’s a possible solution using a Common Table Expression:
sql - User
I wanna to change View, not to create new entities
- Assistant
If you're looking to modify an existing SQL Server view that excludes certain rows based on your specified criteria (where an
EventTypeof 'A' occurs after anEventTypeof 'B' for the same ), you can do that directly within the or statement without creating new entities like CTEs or temporary tables. - User
Is it hiding 1 row or several row?
- Assistant
The SQL provided in the previous example is designed to exclude all rows with
EventType = 'A'that occur after any row withEventType = 'B'for the sameNumber. Therefore, if multiple rows ofEventType = 'A'exist after any row ofEventType = 'B'for a givenNumber, all such rows withEventType = 'A'will be hidden from the view.Example Scenario
Let’s illustrate this with an example:
- User
Theres problem. I wanna hide after EventType = B only one row with EventType = A which going right after after row with EventType = B with ORDER BY EventDT
- Assistant
- User
I have another column in View - EventData and i wanna to add in that code new task - i wanna in my view Value in EventData from row which i hide to put in value of EventData of row that previous of row which i hide
- Assistant