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;
}
Saturday, February 28, 2009
Validate ZIP in Java Script
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
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.
Identity in SQL Server
@@IDENTITY
Returns the last-inserted identity value.
After an INSERT, SELECT INTO, or bulk copy statement completes, @@IDENTITY contains the last identity value generated by the statement. If the statement did not affect any tables with identity columns, @@IDENTITY returns NULL. If multiple rows are inserted, generating multiple identity values, @@IDENTITY returns the last identity value generated. If the statement fires one or more triggers that perform inserts that generate identity values, calling @@IDENTITY immediately after the statement returns the last identity value generated by the triggers. If a trigger is fired after an insert action on a table that has an identity column, and the trigger inserts into another table that does not have an identity column, @@IDENTITY will return the identity value of the first insert. The @@IDENTITY value does not revert to a previous setting if the INSERT or SELECT INTO statement or bulk copy fails, or if the transaction is rolled back.
@@IDENTITY, SCOPE_IDENTITY, and IDENT_CURRENT are similar functions in that they return the last value inserted into the IDENTITY column of a table.
@@IDENTITY and SCOPE_IDENTITY will return the last identity value generated in any table in the current session. However, SCOPE_IDENTITY returns the value only within the current scope. @@IDENTITY is not limited to a specific scope.
INSERT INTO jobs (job_desc,min_lvl,max_lvl)VALUES ('Accountant',12,125)
SELECT @@IDENTITY AS 'Identity'
Error Numbers in SQL Server
@@ERROR
Returns the error number for the last Transact-SQL statement executed.
When SQL Server completes the execution of a Transact-SQL statement, @@ERROR is set to 0 if the statement executed successfully. If an error occurs, an error message is returned.
@@ERROR returns the number of the error message until another Transact-SQL statement is executed. You can view the text associated with an @@ERROR error number in the sysmessages system table.
Because @@ERROR is cleared and reset on each statement executed, check it immediately following the statement validated, or save it to a local variable that can be checked later.
USE pubs
GO
UPDATE authors SET au_id = '12345'
WHERE au_id = "54321"
IF @@ERROR = 547
print "A check constraint violation occurred"
Active Connections in SQL Server
@@CONNECTIONS
Returns the number of connections, or attempted connections, since SQL Server was last started.
Connections are different from users. Applications, for example, can open multiple connections to SQL Server without the user observing the connections.
To display a report containing several SQL Server statistics, including connection attempts, run sp_monitor.
@@CONNECTIONS AS 'Login Attempts'
How to Get SQL Server Version
@@VERSION
Returns the date, version, and processor type for the current installation of SQL Server.
The information returned by @@VERSION is similar to the product name, version, platform, and file data returned by the xp_msver stored procedure, which provides more detailed information.
SELECT @@VERSION
Active transactions for the current connection
@@TRANCOUNT
Returns the number of active transactions for the current connection.
The BEGIN TRANSACTION statement increments @@TRANCOUNT by 1. ROLLBACK TRANSACTION decrements @@TRANCOUNT to 0, except for ROLLBACK TRANSACTION savepoint_name, which does not affect @@TRANCOUNT. COMMIT TRANSACTION or COMMIT WORK decrement @@TRANCOUNT by 1.
BEGIN TRANSACTION
UPDATE authors SET au_lname = upper(au_lname)
WHERE au_lname = 'White'
IF @@ROWCOUNT = 2
COMMIT TRAN
IF @@TRANCOUNT > 0
BEGIN
PRINT 'A transaction needs to be rolled back'
ROLLBACK TRAN
END
Sunday, February 8, 2009
Google Maps in ASP.NET
I came accross very good article on integrating google maps into ASP.NET application.
Basically we need to build one ASP.NET Server control that would allow us to harness the power of Google Maps in the code-behind model.
Check out the below link for complete information:
http://dotnet.sys-con.com/node/171162
Member of The Year Award from DotNetSpider
This time the Annual Super Gift Award goes to Mr. VIJAYA KRISHNA.
OUR HEARTY CONGRATULATIONS TO Mr. VIJAYA KRISHNA.
Members please join with me to congratulate him. The winner will be awarded with DIGITAL CAMERA.
Mr.Vijaya Krishna is one of the most active members of DotNetSpider. He joined DotNetSpider on 21st August, 2004. He received a couple of awards/gifts from DotNetSpider. He also got MVP award from Microsoft in the year 2008.
We can see the announcement of this award here: http://www.dotnetspider.com/forum/174149-Microsoft-MVP-Award-Vijaya-Krishna.aspx
He is also maintaining a blog on Microsoft Technologies. We can see his blog at : http://dotnetvj.blogspot.com. He has contributed a lot in the area of VB.NET, ASP.NET with SQL Server.
We can see his profile at the URL:
http://www.dotnetspider.com/member/vijay_birju.aspx.
Once again CONGRATULATIONS to Mr. Vijaya Krishna. Keep it up Vijaya.
One Cube Query Engine
"One Cube" stands for Oracle, SQL Server and Sybase.
"Query Engine" A place to resolve all the issues related to Database.
In this IT world, Database plays major/critical role in any applications. The main purpose of this group is to bring Oracle, SQL Server and Sybase at one place to resolve all the queries or provide extensive information on these.
In addition to this, community also address the queries related to DB2, My SQL and Informix.
You can use this community in following ways:
1) Knowledge sharing
2) Certification Preparation
3) Career Guidance
4) Interview preparation
If you are looking for a strong foundation in the database world or want to clear database certifications then, you are at the right place.
http://www.dotnetspider.com/sites/281/-One-Cube-Query-Engine.aspx
Microsoft Certifications
Hi
Just wanted to share good news with you...
Now you can get 10% on Microsoft Certifications...
Certification Promotion Code: "IN7DE629"
Just use this promotion code and get 10% off, there is no limit on this... Discount Voucher Code to receive a 10% discount off an applicable Microsoft Certification exam until March 31, 2009.
Discount Voucher can be utilized to sit for any of the New Generation of Certifications i.e. Microsoft Certified Technical Specialist (MCTS), Microsoft Certified IT Professional (MCITP) and Microsoft Certified Professional Developer (MCPD) exams until May 31, 2009.
If an exam candidate fails an exam on his/her first attempt, they can use the same Discount Voucher Code to retake the same exam for free.
All retake exams must be completed by May 31, 2009 and are subject to compliance with Microsoft Certification Exam Retake Rules.
Not valid for 072-series exam.
Sunday, February 1, 2009
code analysis for C#
StyleCop is a free static code analysis tool from Microsoft that checks C# code for conformance to StyleCop's recommended coding styles and a subset of Microsoft's .NET Framework Design Guidelines. StyleCop analyzes the source code, allowing it to enforce a different set of rules from FxCop. The rules are classified into the following categories:
Documentation
Layout
Maintainability
Naming
Ordering
Readability
Spacing
StyleCop includes both GUI and command line versions of the tool.
Code Analysis in .Net
FxCop is a free static code analysis tool from Microsoft that checks .NET managed code assemblies for conformance to Microsoft's .NET Framework Design Guidelines. Unlike the Lint programming tool for the C programming language, FxCop analyzes the compiled object code, not the original source code. It uses MSIL parsing, and callgraph analysis to inspect assemblies for more than 200 defects in the following areas:
Correctness
Library design
Localization
Naming conventions
Performance
Security
FxCop includes both GUI and command line versions of the tool. Microsoft Visual Studio 2005 and Visual Studio 2008 Team System Development Editions both include a "Code Analysis" feature based on FxCop.
differences strored procedures and triggers
Stored Procedure:
A stored procedure can be created with no parameters, IN parameters, OUT parameters. There can be many parameters per stored procedure.
One has to manually call this Object to do some actions.
Trigger:
It is a fragment of code that tells Database to fire or run BEFORE or AFTER a table is modified.
It has the power to make sure that a column is filled in with default information make sure that an audit row is inserted into another table after finding that the new information is inconsistent with other stuff in the database.
Cursors in SQL Server
SQL Server is very good at handling sets of data. For example, you can use a single UPDATE statement to update many rows of data. There are times when you want to loop through a series of rows a perform processing for each row. In this case you can use a cursor.
cursors are the SLOWEST way to access data inside SQL Server. The should only be used when you truly need to access one row at a time. The only reason I can think of for that is to call a stored procedure on each row.
cursors are over thirty times slower than normal SQL queries.
Reference : http://www.sqlteam.com/article/cursors-an-overview
differences between primarykey and uniquekey
One of the basic question in any interviews is What is the difference between primary key and unique key?
Just give the below ponts, he/she will be very happy with the answers.
The Major differences between Primary Key and Unique Key are:
1) Primary Key doesn't allow null values, But Unique key does all nulls(Only One per key).
2) You can have No.Of Unique Keys on a single table, but you can have atmost only one primary key.
3) Primary Keys are used to define Referential Integrity Constraints.