Link to home
Start Free TrialLog in
Avatar of DarrenJackson
DarrenJacksonFlag for United Kingdom of Great Britain and Northern Ireland

asked on

max statment in sql 2008 not working

Guys

I am trying to do a max statement on the following t-sql

select 
udb.fk_cmdb_id,
udb.ad_login,
udb.fullname,
udb.firstname,
udb.surname,
udb.job_title, 
udb.department, 
udb.mobiletel,
udb.faxtel,
udb.email,
udb.user4,
udb.location,
udb.site,
udb.postcode,
udb.telext,
udb.fk_company_id,
udb.companyname,
udb.fk_manager,
udb.status, 
cmdb.ck_config_item, 
cmdb.ck_config_type, 
cmdb.cmdb_status, 
cmdb.fk_status_level, 
cmdb.fk_userdb, 
cmdb.pk_auto_id, 
max((convert(varchar, DATEADD(second, diary.updatedonx, '19700101') ,121))) as date1 ,
diary.updatetxt, 
diary.analystid, 
diary.udcode, 
diary.udsource, 
diary.fk_ci_id, 
diary.pk_auto_id 

from 

config_itemi cmdb, 
userdb udb, 
config_diary diary  

where 

cmdb.fk_userdb = udb.keysearch 
and cmdb.pk_auto_id = diary.fk_ci_id 
and cmdb.ck_config_type like 'HARDWARE%' 

group by

udb.fk_cmdb_id,
udb.ad_login,
udb.fullname,
udb.firstname,
udb.surname,
udb.job_title, 
udb.department, 
udb.mobiletel,
udb.faxtel,
udb.email,
udb.user4,
udb.location,
udb.site,
udb.postcode,
udb.telext,
udb.fk_company_id,
udb.companyname,
udb.fk_manager,
udb.status, 
cmdb.ck_config_item, 
cmdb.ck_config_type, 
cmdb.cmdb_status, 
cmdb.fk_status_level, 
cmdb.fk_userdb, 
cmdb.pk_auto_id, 
diary.updatetxt, 
diary.analystid, 
diary.udcode, 
diary.udsource, 
diary.fk_ci_id, 
diary.pk_auto_id 

Open in new window


it errors with msg

The text, ntext, and image data types cannot be compared or sorted, except when using IS NULL or LIKE operator.

the field  diary.updatedonx that is getting maxed is originally in seconds and im converting it to a date time and now want to just return the lastest line

Any ideas

Regards
SOLUTION
Avatar of Brian Crowe
Brian Crowe
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of DarrenJackson

ASKER

I've proportioned points as I appreciated all the help.

Thanks