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 2008 Forums
 Transact-SQL (2008)
 Help with query

Author  Topic 

nhess80
Yak Posting Veteran

83 Posts

Posted - 2009-12-03 : 15:00:01
For some reason when I run my query like this below it works fine. But the second way when I add LEFT() or Group by it returns nothing. I don't understand why this is.

Thanks,

Nick


----------------------WORKS------------------------------------


Select LRN

FROM CDRS

Where (DateTimeInt Between 1257033600 AND 1257119999) AND
(OrigGw = 'GB-GW2') AND
(OrigPort = '3') AND
(RoundDuration > 0)AND
(Revenue / RoundDuration *60 = 0.017)

Order by LRN




----------------DOES NOT WORK---------------------------

Select LEFT(LRN,6)

FROM CDRS

Where (DateTimeInt Between 1257033600 AND 1257119999) AND
(OrigGw = 'GB-GW2') AND
(OrigPort = '3') AND
(RoundDuration > 0)AND
(Revenue / RoundDuration *60 = 0.017)

GROUP BY LEFT(LRN,6)
Order by LEFT(LRN,6)

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2009-12-03 : 15:12:34
Since you aren't using any aggregate functions in the SELECT, why not just use DISTINCT instead?

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog

"Let's begin with the premise that everything you've done up until this point is wrong."
Go to Top of Page

nhess80
Yak Posting Veteran

83 Posts

Posted - 2009-12-03 : 15:22:53
Whenever I add anything like that "DISTINCT, LEFT()" I don't get an error, it just wont return any results and it seems to be because of this "(Revenue / RoundDuration *60 = 0.017)" in the where clause. When I remove that, it works but I need that in there


quote:
Originally posted by tkizer

Since you aren't using any aggregate functions in the SELECT, why not just use DISTINCT instead?

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog

"Let's begin with the premise that everything you've done up until this point is wrong."

Go to Top of Page

vijayisonly
Master Smack Fu Yak Hacker

1836 Posts

Posted - 2009-12-03 : 15:35:09
Try this in your "where"...

Where (DateTimeInt Between 1257033600 AND 1257119999) AND
(OrigGw = 'GB-GW2') AND
(OrigPort = '3') AND
(RoundDuration > 0)AND
(convert(decimal(10,3),(Revenue * 1.0) / RoundDuration *60) = 0.017)


Go to Top of Page

nhess80
Yak Posting Veteran

83 Posts

Posted - 2009-12-03 : 15:49:06
Yes this worked. Can you please explain why this worked???

THank you very much


quote:
Originally posted by vijayisonly

Try this in your "where"...

Where (DateTimeInt Between 1257033600 AND 1257119999) AND
(OrigGw = 'GB-GW2') AND
(OrigPort = '3') AND
(RoundDuration > 0)AND
(convert(decimal(10,3),(Revenue * 1.0) / RoundDuration *60) = 0.017)




Go to Top of Page

vijayisonly
Master Smack Fu Yak Hacker

1836 Posts

Posted - 2009-12-03 : 15:53:52
I'm converting the value to a 3-point decimal using the convert statement since u wanted it to compare with "0.017"...

The reason I multiplied by 1.0 is explained in the link below..

http://sqlblogcasts.com/blogs/madhivanan/archive/2008/01/16/beware-of-implicit-conversions.aspx
Go to Top of Page
   

- Advertisement -