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 |
alejo46
Posting Yak Master
157 Posts |
Posted - 2013-04-24 : 18:17:39
|
Good afternoonim 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 daythe FEC_SALDO is smalldatetime 4 and the format is like this Fec_saldo2012-07-12 00:00:002012-07-12 00:00:00 this is the query: select FEC_SALDO, count(*)from SALDOS_PREPAGO_DIARIOS_ALTAMIRA_SALDOSwhere 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 examplewhere FEC_SALDO >= '20120703'and FEC_SALDO <= '201207004'it yields me the same number of recordsi dont know if it has something to do with the date formatthanks in advanced |
|
James K
Master Smack Fu Yak Hacker
3873 Posts |
Posted - 2013-04-24 : 18:37:24
|
quote: Originally posted by alejo46 Good afternoonim 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 daythe FEC_SALDO is smalldatetime 4 and the format is like this Fec_saldo2012-07-12 00:00:002012-07-12 00:00:00 this is the query: select FEC_SALDO, count(*)from SALDOS_PREPAGO_DIARIOS_ALTAMIRA_SALDOSwhere 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 examplewhere FEC_SALDO >= '20120703'and FEC_SALDO <= '201207004'it yields me the same number of recordsi dont know if it has something to do with the date formatthanks 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' |
|
|
alejo46
Posting Yak Master
157 Posts |
Posted - 2013-04-24 : 19:54:14
|
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 |
|
|
MuMu88
Aged Yak Warrior
549 Posts |
Posted - 2013-04-24 : 20:11:50
|
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. |
|
|
|
|
|