2 December 2011

Dynamic Stored Procedure example in Sql Server


Dynamic Stored Procedure example in Sql Server
/*
EXEC Proc_get_gridCount 'MUser','StatusId=1'
--Dynamic Stored Procedure example , to get the table and name and Condition and get the result
*/


Create Procedure Proc_get_gridCount(
@Tablename as varchar(50),
@Condition as varchar(300)
)

as

begin

set nocount on

declare @StrSelectSQL as nvarchar(500)  --It should be nvarchar, if you declare varchar error will come.
SELECT @StrSelectSQL = ''                                

SELECT @StrSelectSQL = @StrSelectSQL + ' Select Count(*) From '    
SELECT @StrSelectSQL = @StrSelectSQL +  @TableName                  
SELECT @StrSelectSQL = @StrSelectSQL + ' Where '
SELECT @StrSelectSQL = @StrSelectSQL + @Condition

 -- print @StrSelectSQL
     
EXEC SP_EXECUTESQL @StrSelectSQL  


END

Check String is Null or Empty in Sql Server


Check String is Null or Empty in Sql Server

  if LTRIM(RTRIM(@Condition))<>'' and (@Condition IS NOT NULL)
  begin
 
  end
  else
 
  begin
 
  end


24 November 2011

When to Use Structure?


When to Use Structure?

Do not define a structure unless the type has all of the following characteristics:

-It logically represents a single value, similar to primitive types (integer, double, and so on).

-It has an instance size smaller than 16 bytes.

-It is immutable[whose state cannot be modified after it is created].

-It will not have to be boxed frequently.

When to Use Delegates Instead of Interfaces ?


When to Use Delegates Instead of Interfaces ?

Both delegates and interfaces allow a class designer to separate type declarations and implementation. A given interface can be inherited and implemented by any class or struct;

A delegate can created for a method on any class


Use a delegate when:

-An eventing design pattern is used.

-It is desirable to encapsulate a static method.

-The caller has no need access other properties, methods, or interfaces on  the object implementing the method.

-Easy composition is desired.

-A class may need more than one implementation of the method.

Use an interface when:

There are a group of related methods that may be called.

A class only needs one implementation of the method.

The class using the interface will want to cast that interface to other interface or class types.

The method being implemented is linked to the type or identity of the class: for example, comparison methods.

21 November 2011

When to Use Inheritance ?


When to Use Inheritance ?



Inheritance is a good choice when:
  • Your inheritance hierarchy represents an "is-a" relationship and not a "has-a" relationship.
  • You can reuse code from the base classes.
  • You need to apply the same class and methods to different data types.
  • The class hierarchy is reasonably shallow, and other developers are not likely to add many more levels.
  • You want to make global changes to derived classes by changing a base class.
  • Composition – Composition is used when the two class has-a relationship among classes
    Inheritance – Inheritance is used when the derived class is-a relationship base class

    For example :
    Take two class
    1.House owner
    2.House

    House owner is a House is not valid - Inheritance
    House owner has a house is valid - Composition

    For example :
    Take two class
    1.Game
    2.Cricket


    Cricket is a game is valid - Inheritance
    Cricket has a game is invalid - Composition

14 November 2011

Empty all table values in the Database


Empty all table values in the Database

CREATE PROCEDURE SP_EmplyAllTableValues
AS
EXEC sp_MSForEachTable 'ALTER TABLE ? NOCHECK CONSTRAINT ALL'
EXEC sp_MSForEachTable 'DELETE FROM ?'
EXEC sp_MSForEachTable 'ALTER TABLE ? CHECK CONSTRAINT ALL'
GO

exec SP_EmplyAllTableValues

Stack and Queue Realtime example and System Example:


Stack and Queue Realtime example and System Example:

Queuing Example[FIFO]

System  : Message Queue - MSMQ
Real Time:The bullet in a machine gun

Stack Example[LIFO]

System : Memory Allocation in System
Real Time:The tennis balls in their container


Consistency level in Azure cosmos db

 Consistency level in Azure cosmos db Azure Cosmos DB offers five well-defined consistency levels to provide developers with the flexibility...