mysql - MSSQL - Can select only columns in a row that have different values -


imagine, have audit table contains following columns:

id   schedule   weekday   weekday_old   weekend   weekend_old 1    week1      m,t,w     th,f          sa,su     sa,su 1    week2      m,t,w     m,t,w         sa,su     sa,su 1    week3      m,t,w     w,th,f        sa,su     sa 1    week4      m,t,w     m,t,w         sa,su     sa,su 1    week5      m,t,w     m,t,w         sa,su     sa,su 1    week6      m,t,w     m,t,w         sa        su     1    week7      m,t,w     m,t,w         sa        su   

is there sql command(s) allow me select rows data in weekday/weekday_old different, or weekend/weekend_old different, or (when weekday/weekday_old , weekend/weekend_old) different , replace values in columns same null?

so, using above table, following returned

week1      m,t,w     th,f          null     null week3      m,t,w     w,th,f        sa,su    sa week6      null      null          sa        su     week7      null      null          sa        su   

this sounds crazy, try we're asked tools have. looking forward help. thank you.

**i removed week4 results table. typo.

what described doesn't match sample (why week4 selected , not null). assuming typo:

select schedule,  nullif(weekday,weekday_old) weekday, nullif(weekday_old,weekday) weekday_old, nullif(weekend,weekend_old) weekend, nullif(weekend_old,weekend) weekend_old  dbo.mytable   nullif(weekday,weekday_old) not null or nullif(weekend,weekend_old) not null; 

Comments