Wednesday, January 4, 2017

HTML Browser Cache

 what you want is not to deactivate the cache, but to deactivate the history buffer. Different browsers have their own subtle ways to disable the history buffer.
In Chrome (v28.0.1500.95 m) we can do this only by Cache-Control: no-store.
In FireFox (v23.0.1) any one of these will work:
  1. Cache-Control: no-store
  2. Cache-Control: no-cache (https only)
  3. Pragma: no-cache (https only)
  4. Vary: * (https only)
In Opera (v12.15) we only can do this by Cache-Control: must-revalidate (https only).
In Safari (v5.1.7, 7534.57.2) any one of these will work:
  1. Cache-Control: no-store
     in html
  2. Cache-Control: no-store (https only)
In IE8 (v8.0.6001.18702IC) any one of these will work:
  1. Cache-Control: must-revalidate, max-age=0
  2. Cache-Control: no-cache
  3. Cache-Control: no-store
  4. Cache-Control: must-revalidate
    Expires: 0
  5. Cache-Control: must-revalidate
    Expires: Sat, 12 Oct 1991 05:00:00 GMT
  6. Pragma: no-cache (https only)
  7. Vary: * (https only)
Combining the above gives us this solution which works for Chrome 28, FireFox 23, IE8, Safari 5.1.7, and Opera 12.15: Cache-Control: no-store, must-revalidate (https only)
Note that https is needed because Opera wouldn't deactivate history buffer for plain http pages. If you really can't get https and you are prepared to ignore Opera, the best you can do is this:
Cache-Control: no-store

Below shows the raw logs of my tests:
HTTP:
  1. Cache-Control: private, no-cache, no-store, must-revalidate, max-age=0, proxy-revalidate, s-maxage=0
    Expires: 0
    Pragma: no-cache
    Vary: *

    Fail: Opera 12.15
    Success: Chrome 28, FireFox 23, IE8, Safari 5.1.7
  2. Cache-Control: private, no-cache, no-store, must-revalidate, max-age=0, proxy-revalidate, s-maxage=0
    Expires: Sat, 12 Oct 1991 05:00:00 GMT
    Pragma: no-cache
    Vary: *

    Fail: Opera 12.15
    Success: Chrome 28, FireFox 23, IE8, Safari 5.1.7
  3. Cache-Control: private, no-cache, no-store, must-revalidate, max-age=0, proxy-revalidate, s-maxage=0
    Expires: 0
    Pragma: no-cache
    Vary: *
    Fail: Safari 5.1.7, Opera 12.15
    Success: Chrome 28, FireFox 23, IE8
  4. Cache-Control: private, no-cache, no-store, must-revalidate, max-age=0, proxy-revalidate, s-maxage=0
    Expires: Sat, 12 Oct 1991 05:00:00 GMT
    Pragma: no-cache
    Vary: *
    Fail: Safari 5.1.7, Opera 12.15
    Success: Chrome 28, FireFox 23, IE8
  5. Cache-Control: private, no-cache, must-revalidate, max-age=0, proxy-revalidate, s-maxage=0
    Expires: 0
    Pragma: no-cache
    Vary: *

    Fail: Chrome 28, FireFox 23, Safari 5.1.7, Opera 12.15
    Success: IE8
  6. Cache-Control: private, no-cache, must-revalidate, max-age=0, proxy-revalidate, s-maxage=0
    Expires: Sat, 12 Oct 1991 05:00:00 GMT
    Pragma: no-cache
    Vary: *

    Fail: Chrome 28, FireFox 23, Safari 5.1.7, Opera 12.15
    Success: IE8
  7. Cache-Control: private, no-cache, must-revalidate, max-age=0, proxy-revalidate, s-maxage=0
    Expires: 0
    Pragma: no-cache
    Vary: *

    Fail: Chrome 28, FireFox 23, Safari 5.1.7, Opera 12.15
    Success: IE8
  8. Cache-Control: private, no-cache, must-revalidate, max-age=0, proxy-revalidate, s-maxage=0
    Expires: Sat, 12 Oct 1991 05:00:00 GMT
    Pragma: no-cache
    Vary: *

    Fail: Chrome 28, FireFox 23, Safari 5.1.7, Opera 12.15
    Success: IE8
  9. Cache-Control: no-store
    Fail: Safari 5.1.7, Opera 12.15
    Success: Chrome 28, FireFox 23, IE8
  10. Cache-Control: no-store

    Fail: Opera 12.15
    Success: Chrome 28, FireFox 23, IE8, Safari 5.1.7
  11. Cache-Control: no-cache
    Fail: Chrome 28, FireFox 23, Safari 5.1.7, Opera 12.15
    Success: IE8
  12. Vary: *
    Fail: Chrome 28, FireFox 23, IE8, Safari 5.1.7, Opera 12.15
    Success: none
  13. Pragma: no-cache
    Fail: Chrome 28, FireFox 23, IE8, Safari 5.1.7, Opera 12.15
    Success: none
  14. Cache-Control: private, no-cache, must-revalidate, max-age=0, proxy-revalidate, s-maxage=0
    Expires: Sat, 12 Oct 1991 05:00:00 GMT
    Pragma: no-cache
    Vary: *

    Fail: Chrome 28, FireFox 23, Safari 5.1.7, Opera 12.15
    Success: IE8
  15. Cache-Control: private, no-cache, must-revalidate, max-age=0, proxy-revalidate, s-maxage=0
    Expires: 0
    Pragma: no-cache
    Vary: *

    Fail: Chrome 28, FireFox 23, Safari 5.1.7, Opera 12.15
    Success: IE8
  16. Cache-Control: must-revalidate, max-age=0
    Fail: Chrome 28, FireFox 23, Safari 5.1.7, Opera 12.15
    Success: IE8
  17. Cache-Control: must-revalidate
    Expires: 0
    Fail: Chrome 28, FireFox 23, Safari 5.1.7, Opera 12.15
    Success: IE8
  18. Cache-Control: must-revalidate
    Expires: Sat, 12 Oct 1991 05:00:00 GMT
    Fail: Chrome 28, FireFox 23, Safari 5.1.7, Opera 12.15
    Success: IE8
  19. Cache-Control: private, must-revalidate, proxy-revalidate, s-maxage=0
    Pragma: no-cache
    Vary: *

    Fail: Chrome 28, FireFox 23, IE8, Safari 5.1.7, Opera 12.15
    Success: none
HTTPS:
  1. Cache-Control: private, max-age=0, proxy-revalidate, s-maxage=0
    Expires: 0

    Fail: Chrome 28, FireFox 23, IE8, Safari 5.1.7, Opera 12.15
    Success: none
  2. Cache-Control: private, max-age=0, proxy-revalidate, s-maxage=0
    Expires: Sat, 12 Oct 1991 05:00:00 GMT

    Fail: Chrome 28, FireFox 23, IE8, Safari 5.1.7, Opera 12.15
    Success: none
  3. Vary: *
    Fail: Chrome 28, Safari 5.1.7, Opera 12.15
    Success: FireFox 23, IE8
  4. Pragma: no-cache
    Fail: Chrome 28, Safari 5.1.7, Opera 12.15
    Success: FireFox 23, IE8
  5. Cache-Control: no-cache
    Fail: Chrome 28, Safari 5.1.7, Opera 12.15
    Success: FireFox 23, IE8
  6. Cache-Control: private, no-cache, max-age=0, proxy-revalidate, s-maxage=0
    Fail: Chrome 28, Safari 5.1.7, Opera 12.15
    Success: FireFox 23, IE8
  7. Cache-Control: private, no-cache, max-age=0, proxy-revalidate, s-maxage=0
    Expires: 0
    Pragma: no-cache
    Vary: *
    Fail: Chrome 28, Safari 5.1.7, Opera 12.15
    Success: FireFox 23, IE8
  8. Cache-Control: private, no-cache, max-age=0, proxy-revalidate, s-maxage=0
    Expires: Sat, 12 Oct 1991 05:00:00 GMT
    Pragma: no-cache
    Vary: *
    Fail: Chrome 28, Safari 5.1.7, Opera 12.15
    Success: FireFox 23, IE8
  9. Cache-Control: must-revalidate
    Fail: Chrome 28, FireFox 23, IE8, Safari 5.1.7
    Success: Opera 12.15
  10. Cache-Control: private, must-revalidate, proxy-revalidate, s-maxage=0

    Fail: Chrome 28, FireFox 23, IE8, Safari 5.1.7
    Success: Opera 12.15
  11. Cache-Control: must-revalidate, max-age=0
    Fail: Chrome 28, FireFox 23, Safari 5.1.7
    Success: IE8, Opera 12.15
  12. Cache-Control: private, no-cache, must-revalidate, max-age=0, proxy-revalidate, s-maxage=0
    Expires: Sat, 12 Oct 1991 05:00:00 GMT
    Pragma: no-cache
    Vary: *

    Fail: Chrome 28, Safari 5.1.7
    Success: FireFox 23, IE8, Opera 12.15
  13. Cache-Control: private, no-cache, must-revalidate, max-age=0, proxy-revalidate, s-maxage=0
    Expires: 0
    Pragma: no-cache
    Vary: *

    Fail: Chrome 28, Safari 5.1.7
    Success: FireFox 23, IE8, Opera 12.15
  14. Cache-Control: no-store
    Fail: Opera 12.15
    Success: Chrome 28, FireFox 23, IE8, Safari 5.1.7
  15. Cache-Control: private, no-cache, no-store, max-age=0, proxy-revalidate, s-maxage=0
    Expires: 0
    Pragma: no-cache
    Vary: *

    Fail: Opera 12.15
    Success: Chrome 28, FireFox 23, IE8, Safari 5.1.7
  16. Cache-Control: private, no-cache, no-store, max-age=0, proxy-revalidate, s-maxage=0
    Expires: Sat, 12 Oct 1991 05:00:00 GMT
    Pragma: no-cache
    Vary: *

    Fail: Opera 12.15
    Success: Chrome 28, FireFox 23, IE8, Safari 5.1.7
  17. Cache-Control: private, no-cache
    Expires: Sat, 12 Oct 1991 05:00:00 GMT
    Pragma: no-cache
    Vary: *
    Fail: Chrome 28, Safari 5.1.7, Opera 12.15
    Success: FireFox 23, IE8
  18. Cache-Control: must-revalidate
    Expires: 0
    Fail: Chrome 28, FireFox 23, Safari 5.1.7, 
    Success: IE8, Opera 12.15
  19. Cache-Control: must-revalidate
    Expires: Sat, 12 Oct 1991 05:00:00 GMT
    Fail: Chrome 28, FireFox 23, Safari 5.1.7, 
    Success: IE8, Opera 12.15
  20. Cache-Control: private, must-revalidate, max-age=0, proxy-revalidate, s-maxage=0
    Expires: 0

    Fail: Chrome 28, FireFox 23, Safari 5.1.7, 
    Success: IE8, Opera 12.15
  21. Cache-Control: private, must-revalidate, max-age=0, proxy-revalidate, s-maxage=0
    Expires: Sat, 12 Oct 1991 05:00:00 GMT

    Fail: Chrome 28, FireFox 23, Safari 5.1.7, 
    Success: IE8, Opera 12.15
  22. Cache-Control: private, must-revalidate
    Expires: Sat, 12 Oct 1991 05:00:00 GMT
    Pragma: no-cache
    Vary: *
    Fail: Chrome 28, Safari 5.1.7
    Success: FireFox 23, IE8, Opera 12.15
  23. Cache-Control: no-store, must-revalidate
    Fail: none
    Success: Chrome 28, FireFox 23, IE8, Safari 5.1.7, Opera 12.15

Sunday, June 7, 2015

How to remove duplicate entry from SQL Table?

CaseProblem table has duplicate entry for CaseDetailId 
Id  CasedetailId
1    20152
2    20152 
3    20153
WITH CTE AS(
   SELECT CaseDetailId,
       RN = ROW_NUMBER()OVER(PARTITION BY CaseDetailId ORDER BY CaseDetailId)
   FROM dbo.CaseProblem
)
--select * FROM CTE WHERE  RN > 1   
 Delete  * FROM CTE WHERE  RN > 1

Final Result 
Id  CasedetailId
1    20152
3    20153
2    20152 this record should be delete.

Tuesday, March 10, 2015

Order by Parent Child in Sql server

declare @ParentChild table (ChildID int, ParentID int, Name varchar(50))
insert @ParentChild values
 (1, null, 'First Parent'),
 (2, null, 'Second Parent'), 
 (3, 2, 'Second Child 1'), 
 (4, 1, 'First Child 1'), 
 (5, 2, 'Second Child 2'), 
 (6, 1, 'First Child 2');

    select  *
    from    @ParentChild feat
    order by
            case 
            when ParentID is null 
            then Name
            else    (
                    select  Name

                    from    @ParentChild parent 
                    where   parent.ChildID = feat.ParentID
                    ) 
            end
    ,       case when ParentID is null then 1 end desc
    ,       Name