create table with fields ID, reserved_by,res_date
res_date is datefield like 2010-03-09 00:00:00.000 from
2005 to 2006 any date assume
based on res_date need to slect table and display
based on month (full jan details in database irrespective
of date and year

Answers were Sorted based on User's Feedback



create table with fields ID, reserved_by,res_date res_date is datefield like 2010-03-09 00:00:00.0..

Answer / sandip

//Show records for a given month
SELECT * FROM table_name (NOLOCK)
WHERE SUBSTRING(res_date, 6, 2) = (numeric value for month.
eg 01 for Jan)


//Show all the records sorted by res_date based on month.
SELECT * FROM table_name (NOLOCK)
ORDER BY SUBSTRING(res_date, 6, 2) ASC

Is This Answer Correct ?    3 Yes 0 No

create table with fields ID, reserved_by,res_date res_date is datefield like 2010-03-09 00:00:00.0..

Answer / thangas sujith prabu.s

select * from tablename where res_date>'2010-01-01
00:00:00.000' and res_date<'2010-02-01 00:00:00.000'

Is This Answer Correct ?    2 Yes 1 No

create table with fields ID, reserved_by,res_date res_date is datefield like 2010-03-09 00:00:00.0..

Answer / anilkumar manthena

select * from <Table> where datepart(month,res_date)=1
It will return all the reservations made on Month "January".

Ex:
SELECT DATEPART(month, '2009-02-13 18:35:06.523')
retrieves the value 2.

Is This Answer Correct ?    1 Yes 1 No

Post New Answer

More SQL Server Interview Questions

What is sql server transaction log file?

0 Answers  


What are the steps to follow to configure SQL*Net?

0 Answers   Tech Mahindra,


What are the differences between triggers and stored procedures?

0 Answers  


how to determine the service pack currently installed on sql server? : Sql server database administration

0 Answers  


What is the status of services on passive node for failover cluster in sql server? : sql server database administration

0 Answers  






How to delete exactly duplicate records from a table?

0 Answers  


Differentiate between a having clause and a where clause.

0 Answers  


What are the two authentication modes in sql server?

0 Answers  


How to swap the data of two columns in a table. both the columns containing varchar values.

9 Answers  


Differentiate between a local and a global temporary table?

0 Answers  


What are the steps you should follow to start sql server in single-user mode?

0 Answers  


Do you know how to implement service broker?

0 Answers  


Categories