Wednesday, September 4, 2019

Difference between Redirect and RedirectToAction

RedirectToAction lets you construct a redirect url to a specific action/controller in your application, that is, it'll use the route table to generate the correct URL.
Redirect requires that you provide a full URL to redirect to.
If you have an action Index on controller Home with parameter Id:
  1. You can use RedirectToAction("Index", "Home", new { id = 5 }) which will generate the URL for you based on your route table.
  2. You can use Redirect but must construct the URL yourself, so you pass Redirect("/Home/Index/5") or however your route table works.
  3. You can't redirect to google.com (an external URL) using RedirectToAction, you must use Redirect.
RedirectToAction is meant for doing 302 redirects within your application and gives you an easier way to work with your route table.
Redirect is meant for doing 302 redirects to everything else, specifically external URLs, but you can still redirect within your application, you just have to construct the URLs yourself.
Best Practices: Use RedirectToAction for anything dealing with your application actions/controllers. If you use Redirect and provide the URL, you'll need to modify those URLs manually when your route table changes.

https://www.dotnettricks.com/learn/mvc/return-view-vs-return-redirecttoaction-vs-return-redirect-vs-return-redirecttoroute

Monday, September 2, 2019

Count positive and Negative number

Count positive and Negative number

select Positive = count(case when num>0 then 1 else null end), negative =count(case when num<0 1="" else="" end="" from="" null="" p="" temp="" then="">
Ques : How to create backup table using query
Ans : Select * into table1 from table2.

Ques : How to get emp name whose salary is greater than average salary in the department?

;with as temp1(id, salary)
as
(
    select id avg(salary) as averagesalary from temp group by id
 )   
  select id from temp1 inner join on temp.id=temp1.id where salary>averagesalary  select * from emp e, (select dept,avg(sal) avg_sal from emp group by dept) e1 where e.dept=e1.dept and e.sal > e1.avg_sa

Followers

Link