Here is the deal, i have an SQL database with a Time(7) field, when i make the connection to CR in VS project the CR detects my Time database column as String... or so it makes me believe. i can import all my data from the database but when i try to format the filed in the report using CR formula i get the "to many arguments have been given to this function"
I've read a lot and tied many formulas and still cant correct this issue, my current formula code (as simple as it seems) is:
totext ({Checkin_CheckoutT.Checkin_time}, "hh:mm")
I've tried another code that seems to be on the right track:
Totext(CTime({Checkin_CheckoutT.Checkin_time}), "hh:mm")
but with this one i get the "bad time format string " when i refresh my report.
I've been looking at this the whole day and still no solution...Please Help!
Current software:
SQL managger 2012,
VS 2012,
Sap CR 13.0.5
Time(7) is just a very precise time field, but Crystal (or at least the version being used) was built before Time(7) existed, so it doesn't know what to do with it. The result is a string of the time in hh:mm:ss.nnnnnnn format. If all you need is the hours and minutes in a string, then use Left({Checkin_CheckoutT.Checkin_time}, 5) to pull out the first 5 characters (which would be the hh:mm part).
You can also flip it back to Crystal time afterwards if that is what is needed: CTime(Left({Checkin_CheckoutT.Checkin_time}, 5))
If you Crystal is reading it as a string field and you don't wanna mess with SQL code to convert it this should work. Im pretty sure I remember that SQL time(7) field is in hh:mm:ss.ms
time(tonumber(split({yourtime7string},":")[1]),tonumber(split({yourtime7string},":")[2]),0)
from there right click, format field and tell Crystal how you want it to look.
if you must format it in the formula
totext(time(tonumber(split({yourtime7string},":")[1]),tonumber(split({yourtime7string},":")[2]),0),"HH:mm")
Related
I have a program that is moving data between two tables in a database. For this, I am using a SQL query and the System.Data.SqlClient package.
All of a sudden, this query throws an error when executing.
SQLCommand.ExecuteNonQuery is throwing:
Conversion failed when converting date and/or time from character string.
I have isolated the line with the conversion to:
AND DATEDIFF(dd,GETDATE(),SUBSTRING(a.date, 1, 10))<14
where a.date is the datetime as varchar. The query is a INSERT-SELECT query, and if I run only the SELECT part, it works. Even more strange is that this query works perfectly fine to run in SSMS both with and without data found.
Have anyone else seen this case lately?
where a.date is the datetime as varchar.
well there's your main problem. If you are storing a date/time: use the appropriate storage type in the database. You have a wide range to choose from, for example date, smalldatetime, datetime and datetime2 - and: SQL Server will know how to correctly understand and work with that data.
Ultimately the problem here is that SUBSTRING(a.date, 1, 10) isn't giving a result that SQL Server understands as a date through implicit string conversion operations. This approach is a: inefficient, and b: brittle (especially between cultures), hence why you simply shouldn't do that. If you store the data appropriately: all the problems will go away.
However! You could also use CONVERT to tell SQL Server to interpret the string as a date/time, explicitly telling it the format you expect (as a number code), so that it stands a chance.
If your a.date (and substring) isn't in one of the supported formats: abandon all hope.
BTW; DATEDIFF(dd,GETDATE(),SUBSTRING(a.date, 1, 10))<14 is probably more efficiently done by way of calculating the start-date/end-date of your range once and just comparing with a comparison operator. GETDATE() won't change per row, so "14 days from now" won't change per row. This would make your query a lot more efficient, especially when combined with the correct date/time format - it becomes:
a.date <= #end -- or < #end, or > #end, or >= #end
which can use an index.
Interesting! "No changes has been made to the code, and no new data has entered the queried table since then."
So the question why it doesn't work as the same way really have a many choice for you
Your code just don't run into the problem date data before.
Application server have something changed like date region/culture so it affect the application way of seeing date when communicate with DB server
the 2. but from DB server e.g. Infra team upgrade/patch the DB server, the configuration is affect so this has problem with date format , update/patching Db cause the build-in functions too have upgraded behavior too!)
The statement in double-quote is false.
System.Data.SqlClient 's feature when process the query ?
and so on...
I think finding the causes just from this little information is the very difficult task.
From my little search ,you really should go diving into the query and data as the others tried to suggest.
Conversion failed when converting date and/or time from character string while inserting datetime
I'm helping a friend with a winforms app loaded with crystal reports (two things I generally try to avoid so pardon my ignorance). Anyhow if I have a varchar database field:
2123456789
And want to display it on the **crystal**report as:
(212)-345-6789
How would I go about that without changing the stored procs, or the database data type (not trying to open that can of worms). From what I've been apply to surmise if it was a numeric or int field then I would be able to use the Format Object number tab. However this is not an option due to the datatyping.
EDIT
My goal is Formatting the data in the crystal report or back end code of the crystal report not the database or t-sql. Thanks
Set the field's display-string formula to:
Picture(CurrentFieldValue,"(XXX) XXX-XXXX")
try this:
Mid("2123456789",1,3)+" - "+Mid("2123456789",4,3)+" - "+ Mid("2123456789",7,4)
I have a time field that i would like to represent on a lightswitch screen. They only offer a date time picker and viewer. Does anybody know a work around for this?
I do not want the date, just time. In my database the column is defined as time(7). Just need to get that in Lightswitch now. Help please.
I tried change my database type to varchar and use a regular textbox, however Lightswitch doesn't offer me to format the textbox (e.g. : AM/PM). If I can do that, that it would be a good workaround, however I cannot do that in Lightswitch.
For the control, I'm pretty sure you will be stuck with a Date Time Picker/Viewer unless you create a custom control that will just do time. In that case the Article linked by #MichaelWashington in the answer mentioned by #MattThalman is the way to go.
But as for display, Lightswitch certainly allows you to format it to your liking. Looking at this MSDN article: How to: Format Numbers and Dates in a LightSwitch Application. Basically you would open your table in the Data Designer and then select your Date Time field. In that field's Properties, you can enter a Format Pattern.
From the MSDN article: Reference: Number and Date Formats. A Format Pattern of "t" would result in a displayed result of: 1:45 PM.
#marc_s is correct. Use the appropriate types. Storing dates and times as strings will cause you a massive amount of headaches later on. Don't do it.
I'm not sure as to the ramifications of using a Date Time type in Lightswitch and time(7) is SQL. I would probably just change your database type to datetime or datetime2. If you don't use the date part, so be it. But it will be there later on if the requirements change.
I had the same problem and came up with this solution.
On your datetime control representing your date field, you can use JQuery on the post render event to hide the part you don't want.
myapp.AddEditEvents.FinishTime_postRender = function (element, contentItem) {
// Hide the Date part of the Control by removing the first fieldset tag it comes to,
$(element).find('fieldset:first').remove();
};
I'm kind of in an awkward search and replace situation. I'm developing a new database for the my employer and am now at the process of importing old data into the new MySQL database. The issues I'm at crossroads with is that the old database was a LEGACY database by the name of PC-File which used .dbf files, so I found a dbf viewer that would allow me to export the information into a .csv file, but, one file in particular, has over 5000 records of data with incorrect century dates... instead of displaying 12/28/2012 - it will display 12/28/1998. I have searched up and the down the internet trying to find a way to parse the date information between the year ranges of "01/01/1900 - 01/01/1914" and replace the "19" with "20." And to no avail have I been able to find a successful solution.
I hope my question is clear is enough....
I'm open to solutions with excel, C#, vb.net, and MySQL; any input or advice would be GREATLY appreciated.
Here is a sample of my .CSV file:
"CUSTOMER","ORDER_DATE"
670,"4/18/1913"
670,"6/25/1913"
670,"6/25/1913"
667,"9/18/1912"
665,"9/14/1912"
664,"12/8/1920"
664,"12/8/1920"
658,"9/23/1911"
658,"2/6/1912"
655,"5/11/1911"
651,"12/10/1910"
651,"12/10/1910"
651,"12/14/1910"
648,"6/2/1910"
648,"6/2/1910"
648,"6/2/1910"
648,"6/2/1910"
Thank you guys for any feedback or tips.
If you've got it in a database run the following SQL
MySQL Solution:
update myTable
set ORDER_DATE = DATE_ADD(ORDER_DATE, INTERVAL 100 YEAR)
where ORDER_DATE between '1900-01-01' and '1914-01-01'; /* Change this cutoff date range as appropriate */
Whatever technology you use the logic's the same; select all records for which the date has the wrong year, then correct by adding 100 years.
The Excel solution would be:
=IF(AND(A1>=DATE(1900,1,1),A1<=DATE(1914,1,1)),DATE(YEAR(A1)+100,MONTH(A1),DAY(A1)),A1)
where column A contains your date values.
You should be able to just parse the dates any way you can, check if they're in the 1900-1914 range you specified, and replace the "19" with "20". Here's one way to handle the parsing and subsequent replacement with Regex:
string brokenDate = "648,\"12/10/1912\"";
System.Text.RegularExpressions.Match m = System.Text.RegularExpressions.Regex.Match(brokenDate, #"(\d{1,2}/\d{1,2}/)19(?=(0[0-9]|1[0-4]))");
string fixedDate = m.Groups[1].Value + "20" + m.Groups[2].Value;
You could also alter the Regex to return the whole line if you wanted, instead of just the fixed date as I've done. Or as someone else suggested, it should be possible to modify it a bit to just fix the whole file in one go.
I would like to understand the concept behind this.
I am making a database in c#. Now, I wish to have only date instead of date and time.
So, I went for the following command in sql query pane:
SELECT CONVERT(varchar, deal_start_date, 101) AS 'deal_start_date'
FROM client
The desired result comes but the data becomes read only and hence cant be edited.
Further, it does not stay permanently. I mean,
On clicking show table data again the date-time format comes.
Can any one tell me why the cells become read-only and how to keep the changes permanently through UI only??
Many thanks.
My guess on the read only part, is that since you are now converting the original value, you loose the link towards the column in the database. Just like a computed column can't be edited (how would you for example write to the column from the query that is defined as A+B as 'C'.
Inside what type of component are you showing this in your GUI? Maybe you can ahve your query remain as SELECT deal_start_date FROM client, and filter out the time part from your component?
Or, if you don't use the time in any other place in your application, change the column from datetime to date in the database.
I did not get a perfect answer but I found an alternative. I was trying with datetime datatype in MS SQL database. When I changed it to varchar(12), I got the desired result. i.e in date format.
(Thanks to insights provided by Øyvind Knobloch-Bråthen )
This is actually improper to follow as with size 12 in varchar, the time part is truncated.
(If the size of varchar is increased, the time part will be present)
But It served my purpose.
But I am still waiting for a correct answer,if any.