Codechef4u is a community for computer professionals,by computer professionals,just like you; who loves sharing and helping each others,Join them
Share your post

Bootstrap code

Bootstrap code:

Bootstrap framework allows you to display code using two different tags:

1. Using pre tag

If the code needs to be displayed as a standalone block element or if it has multiple lines, then you should use the <pre> tag.

2. Using code tag

 If you are going to be displaying code inline, you should use the <code> tag.

Example:

With below example I want to display C# LINQ source code using bootstrap source and pre tag

<p>with &lt;pre&gt; tag code as: 
        <pre> var UserDetails = (from userData in DbContext.User where userData.ManagerId == 3
                                select userData).ToList();         
        </pre>
        <p>using code tag.</p>
        <code>
      var UserDetails = (from userData in DbContext.User
                         where userData.ManagerId == 3
                         select userData).ToList();        
  </code>

Output is:


Having Clause with CASE expression

Having Clause with CASE expression

Introduction

My friend asked me a question, “Can I use case statement in a HAVING clause in SQL server?”

I was confused but still answered I think this is possible.

After some tweaks I crated t-sql query that uses case statement in having clause and that experience I shared in this tutorial.

Example:

In this example select statement returns employee with Searched CASE expression which satisfies following condition.

Condition:

Male employee salary is more than “INR 150” per day and female employee salary is more than “INR 180.”

The searched CASE expression evaluates a set of Boolean expressions to determine the result.

Code Sample:

Employee table Data:

 

 

--- Searched CASE expression

SELECT EmployeeName ,Country,CompanyPlant,Gender, Total=MAX(PayScale)

FROM Employee

GROUP BY EmployeeName ,Country,CompanyPlant,Gender

HAVING (MAX(CASE WHEN Gender = 'Male'

 THEN PayScale

 ELSE NULL END) > 150.00

 OR MAX(CASE WHEN Gender = 'Female'

 THEN PayScale

 ELSE NULL END) > 180.00)

 

Select Query returned Data:


ORDER BY clause with CASE Expressions(CASE STATEMENT)

ORDER BY clause with CASE Expressions(CASE STATEMENT): 

I was googling some code examples on how to use “ORDER BY clause with CASE Expressions (CASE STATEMENT)”, with some googling information I tried following t-sql code and that worked for me.

This experience I want to share in this post with example and code sample.

Searched CASE expression:

The searched CASE expression evaluates a set of Boolean expressions to determine the result.

Example:

In this example searched CASE expression used to decide order, for male all records are in descending order and for female ascending order.

Code sample:

SELECT * FROM dbo.Employee
ORDER BY 
 CASE WHEN Gender='Male' THEN EmployeeName END Desc,
 CASE WHEN Gender='Female' THEN Country END ASC