Search This Blog

Tuesday, February 23, 2010

How to alter a column name of a table using sql query

To update the column name of an sql table find the id of table from sysobjects table and update the syscolumns table as follows.

DECLARE @id INT
SELECT @id=[id] FROM sysobjects WHERE [name] = 'ContactDetails'

UPDATE syscolumns SET [name] ='Users_ID' WHERE [id]=@id AND [name] = 'UserID'

Wednesday, February 10, 2010

How to find the object dependencies using SQL Query

Below is the sql query to find dependencies of a table(ListingHdr).

SELECT TableName, DependentObject
FROM (
              SELECT DISTINCT
                  o.Name 'TableName',
                   op.Name 'DependentObject'
              FROM SysObjects o
               INNER Join SysDepends d ON d.DepId = o.Id
               INNER Join SysObjects op on op.Id = d.Id
               WHERE o.XType = 'U' and o.name = 'ListingHdr'
               GROUP BY o.Name, o.Id, op.Name
) x

Tuesday, January 19, 2010

How to get physical path of a database

Below is the sql statement to get the physical path of a database.

SELECT name, filename FROM SYSFILES

--

Wednesday, January 13, 2010

Database Back up Script

BACKUP DATABASE Database_Name TO DISK = 'D:\\Dms.bak'

Wednesday, January 6, 2010

How to get count in a variable by running a SQL dynamic query

Below is the query to get count in a variable whether the count statement is in a dynamic query.

USE Northwind
DECLARE @tablevariable varchar(100)
SET @tablevariable = 'Categories'

DECLARE @sql nvarchar(4000), @params nvarchar(4000), @count int
SELECT @sql = N' SELECT @cnt = COUNT(*) FROM ' + quotename(@tablevariable)
SELECT @params = N'@cnt int OUTPUT'
EXEC sp_executesql @sql, @params, @cnt=@count OUTPUT
SELECT
@count


Note: sp_executesql is a system defined store procedure

Friday, December 4, 2009

Print web page using JavaScript

function printpr()
{
if (navigator.appVersion.indexOf("IE 5.0")>=0 || navigator.appVersion.indexOf("IE 6.0")>=0)
{
var OLECMDID = 7;
/* OLECMDID values:
• 6 – print
• 7 – print preview
• 1 – open window
• 4 – Save As
*/

var PROMPT = 1; //note PROMPT = 2 -DO NOT PROMPT USER
var WebBrowser = ‘’;
document.body.insertAdjacentHTML(‘beforeEnd’, WebBrowser);
WebBrowser1.ExecWB(OLECMDID, PROMPT);
WebBrowser1.outerHTML = “”;
}
else
{
self.print();
}

}

Tuesday, December 1, 2009

How to display one group per page in a Crystal Report

If your crystal report is grouped by a field and you want to display one group per page of your crystal report then go to section expert of group header( to which you want to display per page), check to New Page Before and write condition as:-

GroupNumber <> PageNumber


After doing above, save the changes. Now it is ready to fulfill your requirement.