Monday, 28 March 2016

NULLIF Function in sql

The NULLIF function takes two arguments. If the two arguments are equal, then NULL is returned. Otherwise, the first argument is returned. The syntax for NULLIF is as follows:
NULLIF ("expression 1", "expressions 2")
It is the same as the following CASEstatement:
SELECT CASE ("column_name")
  WHEN "expression 1 = expression 2 " THEN "NULL"
  [ELSE "expression 1"]
  END
FROM "table_name";
For example, let's say we have a table that tracks actual sales and sales goal as below:
Table Sales_Data
Store_NameActualGoal
Store A5050
Store B4050
Store C2530
We want to show NULL if actual sales is equal to sales goal, and show actual sales if the two are different. To do this, we issue the following SQL statement:
SELECT Store_Name, NULLIF (Actual, Goal) FROM Sales_Data;
Result:
Store_NameNULLIF (Actual, Goal)
Store ANULL
Store B40
Store C25

Sunday, 27 March 2016

Delete duplicate rows in sql using Single query

To delete the Newly inserted Duplicate record :

create table ##temp (id int identity(1,1) primary key  ,name varchar(100) )

insert into ##temp (name) values ('Kumar')
select * from ##temp


insert into ##temp (name) values ('Kumar')
select * from ##temp






Delete a from ##temp a,##temp  b where a.id>b.id and a.name=b.name
select * from ##temp





To delete the Old inserted Duplicate record :

create table ##temp (id int identity(1,1) primary key  ,name varchar(100) )

insert into ##temp (name) values ('Kumar')
select * from ##temp


insert into ##temp (name) values ('Kumar')
select * from ##temp






Delete a from ##temp a,##temp  b where a.id<b.id and a.name=b.name
select * from ##temp




Saturday, 26 March 2016

QueryString Using PostBackUrl

<asp:LinkButton ID="lnkfirstname" runat="server" Text='<%# Eval("firstname") %>' PostBackUrl='<%# String.Format("~/Personal/PersonalDetails.aspx?EMP_ID={0}",Eval("EMP_id")) %>'> </asp:LinkButton>

Saturday, 19 March 2016

Difference between cellpadding and cellspacing

Example 1 clearly illustrates the difference between cellpadding and cellspacing:



Example 1 - (cellpadding="10" cellspacing="10")
tablecells1 (3K)

Example 1 - Legend

 
Cell content

 
Cellpadding

.....
Cell border

 
Cellspacing

 
 
Table border