Sunday 10 December 2017

How To Select a Particular Date From Table in SQL?

// Create Database
Create Database LearningPoint92; 

 //Select Database
Use  LearningPoint92;   
      
//Create table GL

Create table GL (Employee_ID INT  Not NULL,Employee_Name Varchar (20) NOT NULL, Salary  INT  NOT NULL, Dt_time  Date NOT NULL,PRIMARY KEY (Employee_ID));    

//Retrieve from GL
Select * from GL;

//Insert Data into GL

 INSERT into GL(Employee_ID, Employee_Name,Salary, Dt_time) values (237998, 'Ram',89555,'2017-8-21' );
INSERT into GL (Employee_ID, Employee_Name,Salary, Dt_time) values (637908, 'Sham',90000, '2017-8-21' );
INSERT into GL(Employee_ID, Employee_Name,Salary, Dt_time) values (231798, 'Rohan',89555, '2017-8-22' );
INSERT into GL (Employee_ID, Employee_Name,Salary, Dt_time) values (352908, 'Sham',90000, '2017-8-23' );
INSERT into GL (Employee_ID, Employee_Name,Salary, Dt_time) values (685098, 'Rohan',23555, '2017-9-21' );
INSERT into GL (Employee_ID, Employee_Name,Salary, Dt_time) values (658990, 'Ram',89555, '2017-9-22' );

//How to select particular Date from GL
SELECT * FROM GL WHERE CAST (Dt_time as Date) = '2017-08-21';

//Select Date between some Range
SELECT * FROM GL where Dt_time between '2017-08-21' AND '2017-08-23';

//Rename a table  
EXEC sp_rename 'GL','DtTerr';

//Retrieve from DtTerr


Select * from DtTerr;

No comments:

Post a Comment

apply function in R

1) apply function: It takes 3 arguments matrix,margin and function.. Example: m<-matrix(c(1,2,3,4),nrow=2,ncol=2) m #1 indicates it is ap...