Pages

Saturday, February 28, 2009

Validate ZIP in Java Script

Check out the below code to validate zip code.
NOTE: This code is use to validate the Zip Codes in US region only or any Postal code which contains the following format:
nnnnn-nnnn

function ValidateZip(s)
{
reZip = new RegExp(/(^\d{5}$)(^\d{5}-\d{4}$)/);
if (!reZip.test(s))
{
alert("Zip Code Is In-Valid");
return false;
}
return true;

}

CHARINDEX in SQL Server

One of the very intresting question in my mail box is I have INSTR function in oracle and what is equivalent in SQL Server?? In fact this is the easiest way tgo learn new SQL server if you know Oracle or Vice-Versa.

Well the asnwer is CHARINDEX. Check out the below syntax.

CHARINDEX ( expression1 ,expression2 [ , start_location ] )

Searches expression2 for expression1 and returns its starting position if found. The search starts at start_location.

Table Difference in SQL Server

The "tablediff" utility is used to compare the data in two tables for non-convergence. This utility can be used from the command prompt or in a batch file to perform the following tasks:

A row by row comparison between a source table in an instance of Microsoft SQL Server acting as a replication Publisher and the destination table at one or more instances of SQL Server acting as replication Subscribers.

Perform a fast comparison by only comparing row counts and schema.

Perform column-level comparisons.

Generate a Transact-SQL script to fix discrepancies at the destination server to bring the source and destination tables into convergence.

Log results to an output file or into a table in the destination database.

More info on this check out BOL

Wednesday, February 25, 2009

DataTypes in SQL Server

Use the below query to find out the data type of all the columns of a particular table .

SELECT syscolumns.name AS ColumnName, systypes.name AS Datatype
FROM sysobjects, syscolumns, systypes
WHERE sysobjects.id = syscolumns.id
AND syscolumns.xtype = systypes.xtype
AND sysobjects.name = 'table1'

In the above just replace the table1 with the your desired table.

Setting a connection string in Web.Config

Setting a connection string in Web.Config



connectionString="Data Source=Servername;
Initial Catalog=dbo;uid=sa;pwd=sa;Pooling=true;Min Pool Size=0;Max Pool Size=1000;"/>

NestLevel in SQL Server Stored Procedures

@@NESTLEVEL
Returns the nesting level of the current stored procedure execution

Each time a stored procedure calls another stored procedure, the nesting level is incremented. When the maximum of 32 is exceeded, the transaction is terminated.