Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
internsp
Starting Member
1 Post |
Posted - 2010-12-14 : 02:45:03
|
HiCurrently I have a table call tblNames, with only 3 ID inside, primaryKeyID, nameID and dateID.Each nameID has dateID.E.g. 1, James, 12.01.20012, James, 15.01.20053, James, 16.01.20104, Mary, 12.01.20015, Mary, 12.01.2003How do I display names with dates that are not within the last 3 year? Meaning I do not want james to be display.Thanks. |
|
pk_bohra
Master Smack Fu Yak Hacker
1182 Posts |
Posted - 2010-12-14 : 04:04:15
|
Is this ?Declare @Test table(Id int primary key, NameId varchar(50),dateId datetime)Insert into @TestSelect 1, 'James', '2001-12-01' union allSelect 2, 'James', '2005-01-15' union allSelect 3, 'James', '2010-01-16' union allSelect 4, 'Mary', '2001-01-12' union allSelect 5, 'Mary', '2003-01-12'Select distinct NameID from @Test where nameid not in (select Nameid from @test where dateid >dateadd(yy,-3, getdate())) |
 |
|
kashyap.2000
Starting Member
22 Posts |
Posted - 2010-12-14 : 04:26:35
|
select * from [Put your table name here] where datediff(mm,dateID,getdate())<=36Failures will either break you or will make you a better perosn.... |
 |
|
|
|
|
|
|