Saturday, August 22, 2015

How to create a table in sql server DB



How to create a table in sql server DB


CREATE TABLE tblMaster
  (
         RecID        Numeric(6),
         RecTitle     VARCHAR(100),
         RecCode      VARCHAR(10) NOT NULL,
         DataType     Numeric (2) NOT NULL,
         IsDefault    Numeric (1) NOT NULL default(0),
         RecDesc1     Numeric (2),
         RecDesc2     VARCHAR(50),
         RecDesc3     VARCHAR(50),
         ReffRecId    Numeric (6),
    InsertedBy VARCHAR(15)not null,
    InsertedOn DATE not null,
    UpdatedBy  VARCHAR(15) not null,
    UpdatedOn  DATE not null,
    IsActive   CHAR(1) not null DEFAULT('Y'),

         PRIMARY KEY ( RecID ),
         Unique(RecCode),
         FOREIGN KEY(RecID) REFERENCES tblMaster(RecID)
  );

Tuesday, August 18, 2015

STORED PROCEDURE

 

CREATE PROCEDURE [dbo].[proc_Get_StateWiseParticipants] 
 --exec proc_Get_StateWiseParticipants 32   
                  
  @FiscalYrId NUMERIC(5)               
     
  AS   
     
  DECLARE @Sql AS NVARCHAR(1000)    
  DECLARE @Cond AS NVARCHAR(500)    
  DECLARE @ParamDef AS NVARCHAR(300)   
     
  BEGIN    
     
  IF NOT @FiscalYrId=-1   
  SET @Cond=' AND FiscalYrId=@FiscalYrId'     
  ELSE   
  SET @Cond=''   
     
   
     
  SET @Sql='SELECT GradeName,  SUM(Overseas)AS Overseas,SUM(InCountry) AS InCountry,SUM(InHouse)AS InHouse  FROM VW_StateWiseparticipants WHERE 1<>2  '   
     
  SET @Sql=@Sql+@Cond +'  GROUP BY GradeName'   
     
         
SET @ParamDef='@FiscalYrId NUMERIC(5)'        
       
 EXECUTE SP_EXECUTESQL   
 @Sql,   
 @ParamDef,     
 @FiscalYrId  
 END