How to use CASE in Where Condition

How to use CASE in Where Condition

We had a situation in which we had to use case in where condition. This post helps in understanding “How to use CASE in Where Condition”. Lets consider a situation where we need to write a query which should satisfy the below conditions

1. We will pass a parameter: Department Name
2. If we pass the department name, it should return that dept details
3. If we pass “ALL” as perm value it should return all department details
4. Of course a lot ways to implement this but here intension is how we can use CASE in Where statement

T-SQL Script: How to use CASE in Where Condition

 

DECLARE @Parameter VARCHAR(100)=’Systems Engineering’

SELECT DeptCode, Name, Location, Campus
FROM Dept
WHERE
(
CASE WHEN  @Parameter <> ‘ALL’ AND Name= @Parameter THEN 1
WHEN  @Parameter= ‘ALL’  THEN 1
END
) = 1

How to use CASE in Where Condition

 

DECLARE @Parameter VARCHAR(100)=’ALL’

SELECT DeptCode, Name, Location, Campus
FROM Dept
WHERE
(
CASE
WHEN  @Parameter <> ‘ALL’ AND Name= @Parameter THEN 1
WHEN  @Parameter= ‘ALL’  THEN 1
END
) = 1

How to use CASE in Where Condition
Posted in SQL Development, SQL Scripts | Tagged , , , | Leave a comment

Visual Studio 2010 SP1 And IE 9.0 Released Today

Visual Studio 2010 SP1 And IE 9.0 Released Today

This post is to give links to the Visual Studio 2010 SP1 And IE 9.0 Released Today

Visual Studio 2010 Service Pack 1 Now Available

http://www.microsoft.com/downloads/en/details.aspx?FamilyID=75568aa6-8107-475d-948a-ef22627e57a5&displaylang=en

Download the release version of IE9,

http://www.beautyoftheweb.com/#/download

 

Posted in Uncategorized | Tagged | Leave a comment

Backup Compression in SQL Server 2008

Backup Compression in SQL Server 2008

Backup Compression in SQL Server 2008  is really a amazing feature. Earlier we used to use litespeed to compress the backup. As we are dealing with the backups that are in 2 GB to 1 TB in size , to move the bkps to remote machines the bkp should be compressed. 

Hence this feature is really saving the Size and Time also. I wondered to see it is also reducing the time also.

I just tested this feature for a small database ,”Optim_Test1″ on my local machine.

Performed the backup with No Compression

Backup Compression in SQL Server 2008

 

Backup Compression in SQL Server 2008:

 

Backup Compression in SQL Server 2008

From the above screens you might have observed that the option WITH COMPRESSION has been showing differences in both Time and Size.

Posted in SQL Server DBA | Tagged , , , , | Leave a comment