Site Sponsored By: SQLDSC - SQL Server Desired State Configuration
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.
Hi again.I'm trying to make datediff retrun results for multiple users.I think this should be easy for you.
select us.username from users as uswhere DATEDIFF(day,convert(nvarchar,getdate(), 113),convert(nvarchar, (select datec from users where users.username =(lower(users.username))),113)) < -8
Of course i get Subquery returned more than 1 value. I know the problem but i cannot make me think of a way to fix this.
sapator
Constraint Violating Yak Guru
462 Posts
Posted - 2010-12-01 : 22:11:22
Hmm.Late me make it more understandable.
SELECT users.username,(DATEDIFF(day, GETDATE(),datec )) AS NumberOfDaysFROM users-- and something likewhere NumberOfDays < -3
That would be ideal if the where clause worked somehow.Edit:Ok for now i just get all the users on a temp table and then do thecomparison.I would prefer to first do the comparison, thus eliminating users but...I'll keep an eye here if someone post some code.
malpashaa
Constraint Violating Yak Guru
264 Posts
Posted - 2010-12-01 : 23:06:40
[code]SELECT username, NumberOfDays FROM (SELECT username, DATEDIFF(DAY, GETDATE(), datec) AS NumberOfDays FROM users) AS U WHERE NumberOfDays < -3[/code]
malpashaa
Constraint Violating Yak Guru
264 Posts
Posted - 2010-12-01 : 23:11:46
Or
SELECT username FROM users WHERE datec < DATEADD(DAY, -3, GETDATE())
sapator
Constraint Violating Yak Guru
462 Posts
Posted - 2010-12-01 : 23:14:23
Yes, i have found it but thanks for posting!
sapator
Constraint Violating Yak Guru
462 Posts
Posted - 2010-12-01 : 23:17:07
Oh the second one suits me better i think.Without the derived table.Thanks!