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 |
|
sqllover
Constraint Violating Yak Guru
338 Posts |
Posted - 2007-03-03 : 04:15:58
|
| hi,this is my spc:select top 1 u.userid, u.user_name, u.password, c.code_description as role_code, u.expiry_date, u.created_date, u.active,convert(varchar,v. user_date, 103) + ' ' + right('0' + stuff(right(convert(varchar,v.user_date, 109), 14), 8, 4, ''), 10) as user_date,v.operation,h.user_name as updatedbyfrom [usermaster] u inner join [codeMaster] c on 'sp'=c.code inner join [HRUser_developerlog] v on u.userid=v.inserted_id and v.operation='update' inner join [usermaster] h on v.userid=h.useridwhere u.userid = '3' order by v. user_dateif i use it gives the v.user_date as fist modified date it is not giving last modified date. select * from HRUser_developerloguser_date operat userid ion2007-01-25 14:28:17.000 insert 12007-01-24 13:02:18.093 insert 42007-03-03 11:30:29.310 update 22007-03-03 11:30:55.373 insert 32007-03-03 11:31:31.717 insert 262007-01-25 14:28:17.000 insert 32007-03-03 11:43:39.733 update 262007-03-03 11:48:04.543 delete 32007-03-03 14:26:22.420 update 32007-03-03 14:27:00.280 update 32007-03-03 14:27:12.013 update 22007-03-03 14:27:35.763 update 12007-02-08 14:28:17.030 update 22007-03-03 14:27:55.967 update 32007-03-03 14:29:18.827 update 32007-03-03 14:30:52.983 update 3so it has to show 2007-03-03 14:30:52.983 but it shows the first updated id only2007-03-03 14:26:22.420please help me to get my need |
|
|
sqllover
Constraint Violating Yak Guru
338 Posts |
Posted - 2007-03-03 : 04:39:35
|
| please sny one reply me it's very urgent please |
 |
|
|
jen
Master Smack Fu Yak Hacker
4110 Posts |
Posted - 2007-03-03 : 04:45:40
|
| --this will give you one row for each operation,userid and latest dateselect max(date),operation,useridfrom table1group by operation,useridnow, you can join this in your query for details, on userid, something like...select .... from masterTable mjoin (select max(date),operation,useridfrom table1group by operation,userid) aon m.userid=a.useridfor operation specific, put a having clause in the first queryHTH--------------------keeping it simple... |
 |
|
|
sqllover
Constraint Violating Yak Guru
338 Posts |
Posted - 2007-03-03 : 04:52:23
|
| hi jen ,canu please modify my coding |
 |
|
|
jen
Master Smack Fu Yak Hacker
4110 Posts |
Posted - 2007-03-03 : 05:09:05
|
not sure if this fits in your schema... also use variables in your filter valuesselect top 1 u.userid, u.user_name, u.password, c.code_description as role_code, u.expiry_date, u.created_date, u.active, convert(varchar,v. user_date, 103) + ' ' + right('0' + stuff(right(convert(varchar,v.user_date, 109), 14), 8, 4, ''), 10) as user_date, v.operation,h.user_name as updatedbyfrom [usermaster] u inner join [codeMaster] c on u.code=c.code inner join (select max(date),operation,userid from hruser_developerlog group by operation,userid having operation='update') v on u.userid=v.inserted_idinner join [usermaster] h on v.userid=h.useridwhere u.userid = '3' and u.code='sp' order by v. user_dateHTH--------------------keeping it simple... |
 |
|
|
sqllover
Constraint Violating Yak Guru
338 Posts |
Posted - 2007-03-03 : 05:34:52
|
hi jen i used this:select top 1 u.userid, u.user_name, u.password, c.code_description as role_code, u.expiry_date, u.created_date, u.active, convert(varchar,v. user_date, 103) + ' ' + right('0' + stuff(right(convert(varchar,v.user_date, 109), 14), 8, 4, ''), 10) as user_date, v.operation,h.user_name as updatedbyfrom [usermaster] u inner join [codeMaster] c on u.code=c.code inner join (select max(v.user_date) from [HRUser_developerlog] v group by user_datev having operation='update' )on u.userid=v.inserted_idinner join [usermaster] h on v.userid=h.useridwhere u.userid = '3' and u.code='sp'order by v. user_datebut it shows the following error:Server: Msg 156, Level 15, State 1, Line 10Incorrect syntax near the keyword 'select'.Server: Msg 156, Level 15, State 1, Line 22Incorrect syntax near the keyword 'on'. quote:
|
 |
|
|
jen
Master Smack Fu Yak Hacker
4110 Posts |
Posted - 2007-03-03 : 05:49:50
|
| you can't get a max(userdate) because that will give you the latest date from EVERYONE... if you want, add another filteralso, how do you join it with just the date?another way is...select....,(select max(userdate) from hruser_developerlog where userid=u.userid and operation='updated')from....--------------------keeping it simple... |
 |
|
|
|
|
|
|
|