Click here to Skip to main content
15,885,365 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
i have one table in that table 12 months column and emp name column means
emp_ name jan feb march april,,,,,,,,,,dec

means all 12 months are there


in my query i am passing today date
my question is
1) if i pass feb-01-2014 as date
i have to display emp_name jan and feb column name

2) if i pass march-02-2014 as date
i have to display emp_name jan feb march column name

3)if i pass may-11-2014 as date
i have to display column like
emp_name jan feb march april may


please can any one give query for my requirement
Posted
Updated 11-Mar-14 1:44am
v2

1 solution

Try
SQL
SELECT * FROM MyTable WHERE DATEDIFF(y, dateColumn, datePassed) = 0
 
Share this answer
 
Comments
Member 10562086 11-Mar-14 8:10am    
Conversion failed when converting date and/or time from character string. this is error i got sir
and what is that dateColumn ???? is this my months column or what sir?
OriginalGriff 11-Mar-14 8:14am    
The name is meant to be a clue: it's the column that holds the date in your database that you want to check...

Stop concatenating strings to form SQL commands! Not only does it leave you wide open to SQL Injection attacks which can damage or destroy your database, it means you get conversion error like this because SQL cannot identify the date format of the data you send it. Get the date into a DateTime object in your code first, then pass that via a Parameterized query instead.
Member 10562086 11-Mar-14 8:37am    
emp_name jan feb march april may june july,,,,december
sachin 5 6 6 6 7 7 5 12
dravid 6 5 7 8 4 7 8 10

declare @ShiftDate datetime='01-02-2014';

here if i pass this date i want output like
empCode jan feb (only jan feb months and empcode )
sachin 5 6
suppose if i pass date as 2-3-2014
my output like
empcode jan feb march
sachin 5 6 6

like this i have to show sir

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900