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 |
|
mike123
Master Smack Fu Yak Hacker
1462 Posts |
Posted - 2007-09-13 : 21:33:01
|
Hi,I'm looking to do a query that brings back all members that joined on a specified date (day and month, year is irrelavant), and their total years of membership.A result would look like thisuserID / membershipYears100 / 1101 / 2etc...Anyone kind enough to help me out on this one? The "joinDate" column stores date and time info so I think that complicates things just slightly as well.Thanks very much!mike123CREATE TABLE [dbo].[tblUserDetails]( [UserID] [int] IDENTITY(1,1) NOT NULL, [joinDate] [datetime] NULL)GO |
|
|
Zoroaster
Aged Yak Warrior
702 Posts |
Posted - 2007-09-13 : 22:46:07
|
quote: Originally posted by mike123 Hi,I'm looking to do a query that brings back all members that joined on a specified date (day and month, year is irrelavant), and their total years of membership.A result would look like thisuserID / membershipYears100 / 1101 / 2etc...Anyone kind enough to help me out on this one? The "joinDate" column stores date and time info so I think that complicates things just slightly as well.Thanks very much!mike123CREATE TABLE [dbo].[tblUserDetails]( [UserID] [int] IDENTITY(1,1) NOT NULL, [joinDate] [datetime] NULL)GO
DECLARE @daymonth char(5)SET @daymonth = '10/10'SELECT UserId, membershipYears = DATEDIFF(year, joinDate, getdate())FROM tblUserDetailsWHERE CONVERT ( char(5), joindate , 101 ) = @daymonth Future guru in the making. |
 |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
|
|
mike123
Master Smack Fu Yak Hacker
1462 Posts |
Posted - 2007-09-14 : 02:38:49
|
| thanks for the suggestions! This function looks great and will come very handy, also got it working with the first suggestionappreciated once again,mike123 |
 |
|
|
|
|
|
|
|