http://feeds.feedburner.com/SpendYourTimeHere-Once

Current Affiares

Monday, July 16, 2012

How to disable back button of your browser window through java script?

Que. How to disable back button of your browser window through java script?
Ans.
<head>
<SCRIPT type="text/javascript">
            window.history.forward();
            function noBack() { window.history.forward(); }
        </SCRIPT>
</head>
<body onload="noBack()"  onunload="">

how to rename table name?

sp_rename 'old_tablename' ,'new_tablename'

How to count no of duplicate record in a field of a table?

select count(*) as 'NoOfRecord',fname from test 
group by fname having count(fname)>1

Sunday, July 15, 2012

How to get a second largest salary from database?

How to get a second largest salary from database?

Below will work in all database----
select * from tablename t where 
2 =(select count(distinct id) from tablename  where t.id<=id)

Below will work in sql server and mysql only ---
select * from tablename where
 id = (select min(id) from 
(select top 3 id from tablename order by id desc) tb)

Wednesday, July 11, 2012

How to search date between two date?

select * from report_mstr where convert(varchar(10),modified_date,120)
between '2012-07-04' and '2012-07-11'
order by modified_date desc
;

How to get the last 7 days values of a datefield in sql server 2005?

Here is the last 7 days values query without including their time ---
report_mstr = table name
modified_date = datefield


select * from report_mstr 
where (convert(varchar(10),modified_date,120)
between convert(varchar(10),(getdate()-6),120) and convert(varchar(10),getdate(),120))
order by modified_date desc;


 --------
select getdate();
->>>> 2012-07-11 15:41:31.547
select getdate()-6; 
->>>>  2012-07-05 15:40:20.983
select convert(varchar(10),getdate(),120);
->>>> 2012-07-11

My Blog List

Popular Posts

All Rights Reserved To SYTHONCE. Ethereal theme. Powered by Blogger.