sql - Create a view with a validation (TSQL) -
i want create view in t-sql. should show kind of "conflicts".
the problem
i not know how create smart statement appropriate logic.
first explanation try
i have table of values sequences. want check if sequence serial (0, 1, 2, etc...). if serial, ok.
the view should show entries non-serial sequence (0, 1, 3, 5, 8, etc.).
the database this:
simplifying problem:
imagine person. if person eats dinner before lunch, there conflict. want show conflicts in view, , people did not obey sequence.
i happy help.
edit
the sequence attribute contains order of meals.
i not sure, interpret need?
sub query:for id's: 1, 2, 4
select id table id not in (select id-1 table)
shows id's no preceding number: 1 , 4
select id table id in (select id-1 table)
shows id's preceding number: 2
joinselect t2.id table t1 left bring together table t2 on t1.id=(t2.id-1)
if t2 null no preceding id. use: t2.[column] = null
sql sql-server tsql
No comments:
Post a Comment