Sunday, November 2, 2008

Query to find duplicate record in SQL server table & store into table

1) Simple query to find duplicate records in SQL server

select a,count(1)
from #temp
group by a
having count(1) > 1
order by count(1) desc

2) Dump the duplicate records into SQL table
create table #temp (a varchar(15),b varchar(15),c int)
insert into #temp
select emp_no,emp_name,count(1)
from employee
group by emp_no,emp_name
having count(1) > 1



drop table #temp

Saturday, September 13, 2008

Query to remove duplicate record from the table - Oracle

SELECT a.Employee_No,a.Employee_Name
FROM Employee_Contact a
where rowid >
(select min(rowid) from Employee_Contact b
where a.Employee_No = b.Employee_No
)

How to flush the word & excel file from the web site, using C#

System.IO.FileInfo file;

here sFile = your virtual file path (/myfiles/abc.xls)

file = new System.IO.FileInfo(sFile);
if (file.Exists)
{
HttpContext.Current.Response.Clear();
HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment;
filename=" + file.Name);

HttpContext.Current.Response.AddHeader("Content-Length", file.Length.ToString());
HttpContext.Current.Response.ContentType = "application/vnd.ms-excel";
HttpContext.Current.Response.WriteFile(file.FullName);
HttpContext.Current.Response.End();
System.GC.Collect();
}
else
{
HttpContext.Current.Response.Write("This file does not exist.");
}

How to kill/close the EXE's using C#

Below is the code to close word/excel exe uisng C#

Process[] eProcess;
eProcess = System.Diagnostics.Process.GetProcessesByName("EXCEL");
eProcess[0].Kill();


Process[] wProcess;
wProcess = System.Diagnostics.Process.GetProcessesByName("WINWORD");
wProcess[0].Kill();

Default redirect to https protocol -- for 403.4 Or 403- IIS setting

Please follow below steps for default redirection.

1) start > run -- type "inetmgr"
2) click ok
3) go to website > default websit
4) right click on default website
5) select properties
6) click on 'custom errors' tab
7) find 403.4 error code
8) give your redirection page path.
like 'c:/inetpub/wwwroot/redirect.htm"


Here is the code for "redirect.htm" page

Default rediret to https protocol -- for 403.4 Or 403

Please follow below steps for default redirection.

1) start > run -- type "inetmgr"
2) click ok
3) goto website > default websit
4) right click on default website
5) select properties
6) click on 'custom errors' tab
7) find 403.4 error code
8) give your redirection page path.
like 'c:/inetpub/wwwroot/redirect.htm"


Here is the code for "redirect.htm" page

How to pass the parameter using Ado.net to SQL & Oracle

1)
To pass parameter in SQL query OR stored procedure
use- NAME = @MYNAME
here- @MYNAME is parameter

2)
To pass parameter in Oracle query OR stored procedure
use: NAME = :MYNAME
here- :MYNAME is parameter