| Author |
Topic |
|
rohit04413
Yak Posting Veteran
72 Posts |
Posted - 2010-06-01 : 00:29:20
|
| i want to store only date in a table in sql server 2005. if i use smalldatetime datatype, then i am getting date and time both.is there any datatype of type Date Only in sql server 2005 ? |
|
|
pk_bohra
Master Smack Fu Yak Hacker
1182 Posts |
Posted - 2010-06-01 : 00:50:14
|
| Datatype to store Only date is introduced in SQL server 2008.In 2005 you need to use datetime or smalldatetime (depending upon your requirement). You can format the datefield and remove the time component before storing the date. |
 |
|
|
pk_bohra
Master Smack Fu Yak Hacker
1182 Posts |
Posted - 2010-06-01 : 00:51:14
|
| And in case you are doing formatting to remove the time component, try to do the same in front end. |
 |
|
|
rohit04413
Yak Posting Veteran
72 Posts |
Posted - 2010-06-01 : 00:56:19
|
quote: Originally posted by pk_bohra Datatype to store Only date is introduced in SQL server 2008.In 2005 you need to use datetime or smalldatetime (depending upon your requirement). You can format the datefield and remove the time component before storing the date.
Actually what i am trying to do is, i am using crystal reports 2008 to generate reports from sql table. here i am using a parameter which is mapped to the datetime field of sql table. i want to use only date in this parameter but i can do so only if the field in sql table is also date only. |
 |
|
|
rohit04413
Yak Posting Veteran
72 Posts |
Posted - 2010-06-01 : 01:05:28
|
| and i am afraid i'll not be able to upgrade to sql server2008. is there another solution for this problem ? |
 |
|
|
rohit04413
Yak Posting Veteran
72 Posts |
Posted - 2010-06-01 : 04:00:01
|
| AnyBody Help please |
 |
|
|
pk_bohra
Master Smack Fu Yak Hacker
1182 Posts |
Posted - 2010-06-01 : 06:52:58
|
| With whatever experience i have with Crystal report, i think that you can pass the date parameter from front end (crystal report) to datetime parameter in SQL.In case you are worried that in the data in the table may have timepart also then you can remove the time part using the below statement.DATEADD(dd, DATEDIFF(dd,0, <your date field>), 0). |
 |
|
|
rohit04413
Yak Posting Veteran
72 Posts |
Posted - 2010-06-02 : 03:17:31
|
quote: Originally posted by pk_bohra With whatever experience i have with Crystal report, i think that you can pass the date parameter from front end (crystal report) to datetime parameter in SQL.In case you are worried that in the data in the table may have timepart also then you can remove the time part using the below statement.DATEADD(dd, DATEDIFF(dd,0, <your date field>), 0).
please help me here....if i select parameter of type Date in crystal reports then i am not able to map it with the field of type smalldatetime in sql table.but if select parameter of type Date Time in crystal report then its ok. but i want date only. please help |
 |
|
|
rohit04413
Yak Posting Veteran
72 Posts |
Posted - 2010-06-02 : 10:37:31
|
| PLease Help !!!! |
 |
|
|
Sachin.Nand
2937 Posts |
Posted - 2010-06-02 : 10:42:20
|
| I think the only way would be to use a varchar field and then convert to datetime wherever you need to use it.PBUH |
 |
|
|
jimf
Master Smack Fu Yak Hacker
2875 Posts |
Posted - 2010-06-02 : 10:55:05
|
| If you send '20050101'( or '01/01/2005') in as a parameter, sql will assume the time piece is 00:00:00. If that's what's in your database then you're good to go. You can also explicitly convert it into a date inside your stored procedure. The dateadd(dd,datediff(day,0,yourDate),0) will strip of the time part of the in the sql table. You can also account for it in your stored porcedure in the where clauseWHERE yourDate >= @inputDate and yourDate < dateadd(day,1,@inputDate)JimEveryday I learn something that somebody else already knew |
 |
|
|
rohit04413
Yak Posting Veteran
72 Posts |
Posted - 2010-06-02 : 14:18:50
|
quote: Originally posted by Idera I think the only way would be to use a varchar field and then convert to datetime wherever you need to use it.PBUH
but if i use a parameter of type varchar in crystal reports then i won't be able to compare dates with it. |
 |
|
|
vijayisonly
Master Smack Fu Yak Hacker
1836 Posts |
Posted - 2010-06-02 : 14:20:35
|
| Did you see Jim's reply. Whats the problem with stripping the time part off with dateadd(dd,datediff(day,0,yourDate),0) or using the yyyyMMdd format. |
 |
|
|
rohit04413
Yak Posting Veteran
72 Posts |
Posted - 2010-06-02 : 14:25:46
|
quote: Originally posted by jimf If you send '20050101'( or '01/01/2005') in as a parameter, sql will assume the time piece is 00:00:00. If that's what's in your database then you're good to go. You can also explicitly convert it into a date inside your stored procedure. The dateadd(dd,datediff(day,0,yourDate),0) will strip of the time part of the in the sql table. You can also account for it in your stored porcedure in the where clauseWHERE yourDate >= @inputDate and yourDate < dateadd(day,1,@inputDate)JimEveryday I learn something that somebody else already knew
may that'll work with asp.net but i am talking about crystal reports. if i create a parameter of type Date in crystal reports and the then try to select records based on the value of this parameter, i am simply not able to do this because when i go to select record section of report then i select the field of sql table, select comparison operator ,when i try to select the parameter created above, its not there in the list because parameter is of type Date and the sql field is of type smalldatetime.i want the report's parameter to be date only but there is no datatype of Date in sql server.Solution? |
 |
|
|
Michael Valentine Jones
Yak DBA Kernel (pronounced Colonel)
7020 Posts |
Posted - 2010-06-02 : 17:11:01
|
| This sounds like a problem with Crystal Reports, not SQL Server. It is easy to do what you want in SQL Server.You should post your question on a Crystal Reports support forum.CODO ERGO SUM |
 |
|
|
mandm
Posting Yak Master
120 Posts |
Posted - 2010-06-02 : 18:00:32
|
| From what I recall of Crystal reports you can create a stored procedure that supplies the data and whatever formatting you want to do to the columns then tie the report to that instead. |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2010-06-03 : 05:50:57
|
| One solution is, goto toolbar in the Report fileReport-->Selection Forumulas-->RecordIn the code window, type{@your_date_parameter}=Date(your_small_datetime_column)MadhivananFailing to plan is Planning to fail |
 |
|
|
kashyap_sql
Posting Yak Master
174 Posts |
Posted - 2010-12-04 : 02:15:05
|
quote: Originally posted by pk_bohra And in case you are doing formatting to remove the time component, try to do the same in front end.
how can be this happens i am using 2005 any suggestionsWith RegardsKashyap M |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2010-12-07 : 02:19:17
|
quote: Originally posted by kashyap_sql
quote: Originally posted by pk_bohra And in case you are doing formatting to remove the time component, try to do the same in front end.
how can be this happens i am using 2005 any suggestionsWith RegardsKashyap M
select dateadd(day,datediff(day,0,getdate()),0)MadhivananFailing to plan is Planning to fail |
 |
|
|
|