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.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 return datediff multiple values.

Author  Topic 

sapator
Constraint Violating Yak Guru

462 Posts

Posted - 2010-12-01 : 21:50:57
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 us
where 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 NumberOfDays
FROM users
-- and something like
where 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 the
comparison.I would prefer to first do the comparison, thus eliminating users but...I'll keep an eye here if someone post some code.
Go to Top of Page

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]
Go to Top of Page

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())

Go to Top of Page

sapator
Constraint Violating Yak Guru

462 Posts

Posted - 2010-12-01 : 23:14:23
Yes, i have found it but thanks for posting!
Go to Top of Page

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!
Go to Top of Page
   

- Advertisement -