November 2, 2006 at 9:23 am
Hello ppl,
I've been trying to have a go now for a few days but have now given up. I hope your brilliant minds can enlighten me here. Its quite a simple thing really which is why its more frustrating! Query as follows:
SELECT citrixfarm.SDB_SESSION.SESSIONSTART,
citrixfarm.LU_APPNAME.APPNAME
FROM citrixfarm.SDB_SESSION
INNER JOIN
citrixfarm.LU_APPNAME
ON
citrixfarm.SDB_SESSION.FK_APPNAMEID = citrixfarm.LU_APPNAME.PK_APPNAMEID
WHERE citrixfarm.LU_APPNAME.APPNAME IN ('DESKTOP', '20 DESKTOP')
This returns
2004-04-05 14:40:23.000 20 DESKTOP
2004-04-05 14:47:36.000 20 DESKTOP
2004-04-07 10:03:01.000 DESKTOP
2004-04-07 11:33:22.000 20 DESKTOP
2004-04-13 10:38:26.000 DESKTOP
2004-04-13 12:00:53.000 20 DESKTOP etc etc (750000 row table)
I want it to diplay
so now I have:
SELECT DISTINCT(SUBSTRING(cast(citrixfarm.SDB_SESSION.SESSIONSTART as varchar(25)),1,11))
FROM citrixfarm.SDB_SESSION
INNER JOIN
citrixfarm.LU_APPNAME
ON citrixfarm.SDB_SESSION.FK_APPNAMEID = citrixfarm.LU_APPNAME.PK_APPNAMEID
WHERE
citrixfarm.LU_APPNAME.APPNAME IN ('DESKTOP', '20 DESKTOP')
GROUP BY citrixfarm.SDB_SESSION.SESSIONSTART
ORDER BY citrixfarm.SDB_SESSION.SESSIONSTART
so I need a count of the simlar rows and this also involves using the distict, count and order by commands but I am failing to get my head around this and also I am now getting
ORDER BY items must appear in the select list if SELECT DISTINCT is specified.
November 2, 2006 at 9:32 am
This may do the trick
SELECT convert(varchar(10), citrixfarm.SDB_SESSION.SESSIONSTART, 103),
count(*) mycount
FROM citrixfarm.SDB_SESSION
INNER JOIN
citrixfarm.LU_APPNAME
ON
citrixfarm.SDB_SESSION.FK_APPNAMEID = citrixfarm.LU_APPNAME.PK_APPNAMEID
WHERE citrixfarm.LU_APPNAME.APPNAME IN ('DESKTOP', '20 DESKTOP')
GROUP BY convert(varchar(10), citrixfarm.SDB_SESSION.SESSIONSTART, 103)
November 2, 2006 at 9:34 am
Try this:
SELECT CONVERT(CHAR(8),citrixfarm.SDB_SESSION.SESSIONSTART,101), COUNT(*)
FROM citrixfarm.SDB_SESSION
INNER JOIN
citrixfarm.LU_APPNAME
ON
citrixfarm.SDB_SESSION.FK_APPNAMEID = citrixfarm.LU_APPNAME.PK_APPNAMEID
WHERE citrixfarm.LU_APPNAME.APPNAME IN ('DESKTOP', '20 DESKTOP')
GROUP BY CONVERT(CHAR(8),citrixfarm.SDB_SESSION.SESSIONSTART,101)
November 2, 2006 at 9:35 am
I guess Daryl beat me to the Post Reply button.
November 2, 2006 at 10:20 am
I AM NOT WORTHY!
Thank you so much guys. AMAZING response time to my very frustrating problem. This forum is by far the best one out there.
Please continue to keep up the good work, it is very much apprecited
November 3, 2006 at 7:01 am
November 3, 2006 at 9:17 am
Hey Pedro,
thats shaved off two seconds! great!
But now I'm getting
2006-05-05 00:00:00.000
2004-07-20 00:00:00.000 etc
How do I trim the trailing zero's without converting it? Is there a function to trim or reformat a date variable?
November 3, 2006 at 9:31 am
CONVERT(CHAR(10), expression, 21) will convert the date to yyy-mm-dd
November 3, 2006 at 9:45 am
Let the application worry about that... unless you have loads of different reports using that query. You could centralize the code. The convert in the select part only shouldn't slow it down much.
November 3, 2006 at 9:51 am
Agree with Ninja, but if you can;t after you get your resut do a
convert(varchar(10), datevalue , 103)
as in previous post, but after you get the reults, if not you query will slow down again.
SELECT convert(varchar(10), Yourdatefield, 103), a.*
FROM (YOUR QUERY) a
November 3, 2006 at 9:59 am
Thanks every1 for the input,
Ninja, tru the convert doesnt slow it down that much. I just wanted to know if there was another way to trim down the date field without resorting to convert.
November 3, 2006 at 10:06 am
The convert in the select is very minor because it won't affect the query plan (data access wise). It'll take a few cpu cycles to do the converts, but I wouldn't expect it to be very big (few ms at most).
A for the trimming part, it can only be executed on a string. And since datetime is a numeric you have no choice but to do conversions.
Viewing 12 posts - 1 through 11 (of 11 total)
You must be logged in to reply to this topic. Login to reply