Click here to Skip to main content
15,893,381 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i want to display a text which will be in particular date range in a table am having two different columns as from date and todate now i want to display the display text in between the dates how do i write query for this
Edit-pashad
SQL
SELECT n.noticetext ,DATEDIFF(DD,n.PeriodFrom,n.PeriodTo) from tbl_Master_NoticeBoard as n inner join tbl_Master_Employee as e on e.Cid=n.DisplayTo where e.EmployeeId='j126' 
Posted
Updated 2-Apr-12 20:24pm
v2
Comments
Prasad_Kulkarni 3-Apr-12 1:07am    
what exactly 'display text' means?? from where you've to get that text, is it from database or somewhere else..
Post some of your db structure if you can, and some more details also
palaniram 3-Apr-12 1:29am    
select n.noticetext ,DATEDIFF(DD,n.PeriodFrom,n.PeriodTo) from tbl_Master_NoticeBoard as n inner join tbl_Master_Employee as e on e.Cid=n.DisplayTo where e.EmployeeId='j126'

in the above query i want to display a noticetext between periodfrom and perioidto dates
palaniram 3-Apr-12 1:31am    
query is not correct plz change it ....
sravani.v 3-Apr-12 1:07am    
Elaborate your question. what is your table structure or data... so that we can help you.
palaniram 3-Apr-12 1:30am    
select n.noticetext ,DATEDIFF(DD,n.PeriodFrom,n.PeriodTo) from tbl_Master_NoticeBoard as n inner join tbl_Master_Employee as e on e.Cid=n.DisplayTo where e.EmployeeId='j126'

in the above query i want to display a noticetext between periodfrom and perioidto dates is the query is correct plz tell me

Hi, Try this: add @FromDate & @ToDate parameters for the date selection & follow the query.
SQL
SELECT 
noticetext ,
FROM tbl_Master_NoticeBoard 
INNER JOIN tbl_Master_Employee ON Cid = DisplayTo 
WHERE EmployeeId='j126'
AND PeriodFrom >= @FromDate AND PeriodTo <= @ToDate
 
Share this answer
 
Do you mean?
SQL
SELECT CONVERT(NVARCHAR, n.PeriodFrom & ' - ' & n.noticetext  & ' - ' & n.PeriodTo) AS [OneColumn]
FROM tbl_Master_NoticeBoard as n inner join tbl_Master_Employee as e on e.Cid=n.DisplayTo
WHERE e.EmployeeId='j126' 


Result:
OneColumn<br />
2011/05/05 - Travel to Berlin - 2011/05/07


Read more about CONVERT[^]
 
Share this answer
 

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