SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 select count() doesnt get the desired results
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

alejo46
Posting Yak Master

Colombia
142 Posts

Posted - 04/24/2013 :  18:17:39  Show Profile  Reply with Quote
Good afternoon
im new a sql server and i tried to count the records for a derired day but it extracts the same name of records for any day

the FEC_SALDO is smalldatetime 4 and the format is like this

Fec_saldo
2012-07-12 00:00:00
2012-07-12 00:00:00
this is the query:



select FEC_SALDO, count(*)
from SALDOS_PREPAGO_DIARIOS_ALTAMIRA_SALDOS
where FEC_SALDO >= '20120701'
and FEC_SALDO <= '201207004'
group by FEC_SALDO

it prints out 100 rows but if i chenged the where clausethe date for example


where FEC_SALDO >= '20120703'
and FEC_SALDO <= '201207004'

it yields me the same number of records

i dont know if it has something to do with the date format


thanks in advanced

James K
Flowing Fount of Yak Knowledge

3589 Posts

Posted - 04/24/2013 :  18:37:24  Show Profile  Reply with Quote
quote:
Originally posted by alejo46

Good afternoon
im new a sql server and i tried to count the records for a derired day but it extracts the same name of records for any day

the FEC_SALDO is smalldatetime 4 and the format is like this

Fec_saldo
2012-07-12 00:00:00
2012-07-12 00:00:00
this is the query:



select FEC_SALDO, count(*)
from SALDOS_PREPAGO_DIARIOS_ALTAMIRA_SALDOS
where FEC_SALDO >= '20120701'
and FEC_SALDO <= '201207004'
group by FEC_SALDO

it prints out 100 rows but if i chenged the where clausethe date for example


where FEC_SALDO >= '20120703'
and FEC_SALDO <= '201207004'

it yields me the same number of records

i dont know if it has something to do with the date format


thanks in advanced


Your date format for the <= condition does not seem right. Should it be '20120704' instead of '201207004'?

You are seeing the same results probably because there is no data that gets excluded when you narrow the range. Change your where clause as shown below and see if you get any rows at all. If the count shows up as zero, then you know.
where FEC_SALDO >= '20120701'
and FEC_SALDO < '20120703'
Go to Top of Page

alejo46
Posting Yak Master

Colombia
142 Posts

Posted - 04/24/2013 :  19:54:14  Show Profile  Reply with Quote
yes you are right, but mistakenly i typed the '201207004', but actually i typed the right one as you suggested and run the query but it yielded me the same amount of records, abd it should bring me fewer records. Thanks again in advanced
Go to Top of Page

MuMu88
Aged Yak Warrior

547 Posts

Posted - 04/24/2013 :  20:11:50  Show Profile  Reply with Quote

When you say your query is not working, does the query return older records (< '20120703') or newer records (>'20120704') or both?
Can you post your table definitions and some of your data.
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.05 seconds. Powered By: Snitz Forums 2000