Having Trouble Converting To Datetime In SQL Import

Jan 13, 2006

Our database gets updated each week with text files spat out by a mainframe. Previously, the database was in Access; we copied and pasted the text files into Excel, ran macros on them to convert the data, then pasted the results directly into Access and this worked fine for us.

Now that we've moved the tables to SQL Server 2000, we're having problems with the data. We wanted to set up DTS packages for each file to just put them directly into SQL Server. This works for pretty much everything except for the dates.

The way the files are set up, they're comma delimited files with quotes around the text and nothing around the dates. The dates don't have any delimiters; they're just listed like 13012006. Every time we try to import these files into SQL, it gripes about the datatypes; we're trying to put the dates into datetime fields but SQL thinks they're strings. Eek! If we put date delimiters (like 13/01/2006) SQL pulls them in fine, but apparently the mainframe lacks the ability to put these delimiters in by itself and still run everything else OK. The person who writes the extracts has to do it in a language called 'Focus' which I've never heard of and don't know anything about, and he says what I'm asking for can't be done. OK...so now what?

I've tried and tried to convert these strings into dates using both CAST() and CONVERT() and just can't manage to do it. I know I'm missing something really obvious here; does anyone have any tips or advice? Thanks in advance.

View 3 Replies


ADVERTISEMENT

Trouble Converting INT To MONEY

Apr 24, 2008

Hi, I'm working on a DB and I'm trying to write some select statements that will display an employee's pay using the CAST and CONVERT functions. However, I can never seem to get commas inserted into the results please help. Here's the SELECT statements, where am I going wrong?

SELECT
'$' + CAST(CONVERT(MONEY, SUM(PROJECT_BUDGET/1.00), 1) AS VARCHAR) AS 'Total Budget'
FROM
PROJECT;

View 5 Replies View Related

Trouble Converting Smalldatetime Column

Aug 21, 2007

I have a data field that's datatype int and I need to convert it to smalldatetime, however, I get one row erroring out due to a typo in the data that has a date of 21190101. What's wrong with my case statement to set that one typo to 20790101?

'SD' = Case When pro_date > 20790000 Then
pro_date = '20790101'
Else CAST(CAST(pro_date AS VARCHAR) AS SMALLDATETIME) End,

View 4 Replies View Related

Trouble Converting Datatype For Database Insert

Dec 7, 2004

Hi,
I need to take a value from a textbox and insert it into a field in my database which takes decimals. My problem, no matter what I try I cannot convert the value so that the database will accept it. This all happens when the submit button is hit on my webpage. Here is the cmdSubmit_click sub code:

Dim surveyNum As Decimal = Decimal.Parse(txtSurveyNum.Text, Globalization.NumberStyles.Number)
myCmd.CommandText = "INSERT INTO survey(ID) VALUES('" & surveyNum & "')"
myCmd.Parameters.Add("surveyNum", SqlDbType.Decimal)
myCmd.Parameters("surveyNum").Value = System.Convert.ToDecimal(txtSurveyNum.Text)

myConn.Open()
Try
myCmd.ExecuteNonQuery()
lblMessage.Text = "Record successfully updated"
Catch
lblMessage.Text = "Query error: " & Err.Description
End Try
myConn.Close()

Thnx in advance, any help would be greatly appreciated.

View 1 Replies View Related

Trouble Converting SELECT To INSERT Statement

Sep 18, 2005

Trying to convert the following SELECT statement into a INSERT statement and having trouble. No doubt this will be a piece of cake to someone. To eventually get this to a trigger stage would be nice, but for the moment I'd settle for just plain SQL. Using MS SQL 2000. The database name is reporting. The table name is CallLog. I'm trying to convert seperate date (RecvdDate) and time (RecvdTime) columns into a single DateTime column. I've scoured a lot of web pages but I'm still lost.

==============

use reporting
go

SELECT RecvdDate + RecvdTime FROM [dbo].[CallLog]

===============

Any help much appreciated.

View 7 Replies View Related

Trouble Converting Nvarchar(10) To Smalldate Time Where ISDATE()=1

Nov 17, 2007



I have a column which is current stored as nvarchar(10), and all of the enteries are either NULL or mm/dd/yyyy.
I am trying to convert the column to smalldatetime using CONVERT or CAST and each time I get an arithmetic overflow error message.
I also tried selecting just the enteries with ISDATE()=1 and converting those to smalldatetime, and still got an arithmetic overflow message.

(I've run ISDATE() several times on the column, and the only rows without ISDATE()=1 are those which have NULL values).

help!

View 3 Replies View Related

Trouble Converting A Varbinary (Object) To A String Through Script Task

Dec 9, 2006

I have an Execute SQL Task that queries for the contents of a file (which is declared as a varbinary type). My SSIS package needs to write these contents into a temporary location, so what I do is that I pass the result into a System.Object variable. I then use that variable in a Script Task.

Problem is whenever I execute my script task and DirectCast or CType the variable to a string (which is what the contents of the file is), I get a "Conversion from type '_ComObject' to type 'String' is not valid."

Any ideas on how to go about this problem?

View 1 Replies View Related

Trouble With Datetime Insert And Update

Apr 7, 2006

I am trying to Insert or Update a record in MSSQL with a datetime variable which is modified using the DateAdd function.

Basically, I have a table of Coupons which need to expire 'x' days in the future. When I use GetDate() for the Issue Date, I have no problems. But then, when I use DateAdd to return a date in the future, I can not Insert or Update this result into the record.

I get various errors having to do with type mismatch or function not found, etc.

Can you see what I might be doing wrong?

Here's the code snippit:
<%
if(Recordset2.Fields.Item("SerialNo").Value <> "") then UpdateExpire__SerNo = Recordset2.Fields.Item("SerialNo").Value
if(DateAdd("d",2,Now) <> "") then UpdateExpire__XD = DateAdd("d",2,Now)
%>
<%
set UpdateExpire = Server.CreateObject("ADODB.Command")
UpdateExpire.ActiveConnection = MM_FreeVB_STRING
UpdateExpire.CommandText = "UPDATE dbo.Coupon SET ExpireDate = " + Replace(UpdateExpire__XD, "'", "''") + " WHERE SerialNo = " + Replace(UpdateExpire__SerNo, "'", "''") + ""
UpdateExpire.CommandType = 1
UpdateExpire.CommandTimeout = 0
UpdateExpire.Prepared = true
UpdateExpire.Execute()
%>

This produces this error:

Microsoft OLE DB Provider for ODBC Drivers error '80040e14'

[Microsoft][ODBC SQL Server Driver][SQL Server]Line 1: Incorrect syntax near '12'.

And it errors at the UpdateExpire.Execute() line.

The code was generated by Dreamweaver.

Thanks.

Lance

View 1 Replies View Related

Trouble With Calendar Control For Datetime Parameter

May 4, 2007

I'm creating a report with a Datetime parameter. There's no available values, so the calendar control comes out automatically when I run/preview the report. Now, when I select the date in my calendar control, say for example I select 2/5/07 (2nd of May) and run the report, it gives me data from 5th of Feb. Can anyone help me with this date format problem ???

Not sure if it's related to my problem, I did edit the language tag in the XML source code of my report to have en-AU so that the dates field is showing in the correct dd/mm/yyyy format.

View 2 Replies View Related

Converting DateTime

Oct 14, 2004

Hello Everyone and thanks for your help in advance. I have an application that inserts a variety of values into a SQL Server database. Among the columns are three DateTime values. I have code working properly on my test server, but when I port the identical code to my production database, I get the following error:

Arithmetic overflow error converting expression to data type datetime. The statement has been terminated

When I remove any type of insert involving date, the application works. I have tried the date in various formats, for instance "09/12/2001" and "20010912", but still get the same error. Obviously, there must be differences in the SQL Servers, but I have never run into this problem before and the current server is running many applications involving dates. I haven't got a clue as to how to solve this problem. Any help is greatly appreciated. Thanks.

View 1 Replies View Related

Converting DateTime

Jul 23, 2005

Hi,When I open a tabe in the SQL enterprise manager I see the Timestamp Fieldin this Format :24/01/2005 16:45:00However when I'm using the Query analyzer or other SQL Client I see theTimestamp Field in this Format :2005-01-24 16:44:59.997Does Anybody know what to do in order to display the Timestamp Field infirst Format (24/01/2005 16:45:00) ?Please Advise,Yariv--Message posted via http://www.sqlmonster.com

View 3 Replies View Related

Converting Int Value To Datetime

May 2, 2006

Hi Guys, Could some help me....I am trying to use the below specified two field from "SysJobHistory"table from "MSDB". Field name "run_date" and "run_time". Both thisfields are of INT data type. Data saved in the above two fields is inthis this format 20060501 and 204001 respectively. I want save the datafrom this two field in another table in date time format. I want towrite a SELECT statement which converts the data from this two fieldsinto date time format so that it could be saved in another table whichhas date time data type column respectively.RegardsDipesh Shah

View 1 Replies View Related

Converting Datetime Int

Jul 20, 2005

I have tables with columns that stores datetime data in int format onSQL server 2000. For example, the datetime for '4/5/200400:00:00.000am' is stored as 1081180800. "4/4/2004 11:59:59.000pm' is1081180799. I need to generate reports that display datetime columnsin "mm/dd/yyyy hh:mn:ss" format with am or pm at the end. Bellow ismy query statment.select iorg_name as org, ref_num as [ticketnum], c_first_name as[firstname], c_last_name as [lastname], sym as type, [description] assummary, status, dateadd(s,open_date,'12/31/1969 08:00:00pm') asopened, dateadd(s,last_mod_dt,'12/31/1969 08:00:00pm') as irt,dateadd(s,close_date,'12/31/1969 08:00:00pm') as closed fromAHD.dbo.HDreports reportview WHERE reportview.open_date >= 1080882000AND reportview.open_date <= 1081227599.The result shows correctly with those records that are in daylightsaving time. Those records in standard time show 1 hour behind.Does anyone know how to make this query correctly display the data inproperly?

View 1 Replies View Related

Converting Numeric To Datetime

Dec 9, 2001

Have imported a file from AS400 into SQL and get the Date numeric as yyyymmdd.
How do I get is as a Datetime.

Example:

Delivery Date 20011201 (numeric)

View 1 Replies View Related

Converting A Datetime Column

Jul 21, 2000

I've got have a populated table and I want to convert a datetime column so it lists the date only (without the time component)
I tried to run this as a script, but returns an error:

update <table>
where <column>=convert(datetime,convert(char10),<column>,101))

When I run only this part, it does strip the date of the time component but it becomes a string, and I need this field stored as a datetime field:

convert(char(10),hire_date,101)

I'd appreciate any suggestions :)

View 1 Replies View Related

COnverting From Char To Datetime

Sep 14, 1998

Everytime I run a simple convert statement, from char to datetime, it works but when I use the `Select Convert(datetime, BeginDate)` in an insert statement it complains with a syntax error on the conversion from char to datetime. E.g.

Insert Into AlaskaData2( CurrIssueDate, InactivationDate)
select Convert (Datetime, CurrIssueDate) CurrIssueDate,
Convert(Datetime, InactivationDate) InactivationDate
from Alaskadata1
go

View 1 Replies View Related

Converting Integer To Datetime

Jul 20, 2005

Hi All,How do you convert int value to datetime datatype in sql servere.g 900mins to hh:mm:ssRegardsOla*** Sent via Developersdex http://www.developersdex.com ***Don't just participate in USENET...get rewarded for it!

View 3 Replies View Related

Converting Nvarchar To Datetime

Jan 17, 2008



i have some fields in SQL Server table as nvarchar(50) and the user actually enters date (example : 02/05/07) now they want those fields to be converted to datetime or small datetime field.

How do i achieve it without losing data?


Thanks
bhu

View 1 Replies View Related

Converting Varchar To DateTime

Sep 17, 2007



Hi,

I wanted to convert the varchar to date time and here is what i am doing


DECLARE @dt VARCHAR(20)

SET @dt = '20070111' -- YYYYMMDD format

select CONVERT(datetime, @dt, 120)


This works perfectly fine and the result would be- 2007-01-11 00:00:00.000

But if i changed my datetime format from YYYYMMDD to YYYYMMDDHHMM then this is failing and throwing

"Conversion failed when converting datetime from character string."

Can any one please let me know how do we achieve this?



~Mohan

View 3 Replies View Related

Need Help Converting A CHAR Into A Datetime

Nov 15, 2006

I have a Database which is having a Counterdate time Column stored in the form of Char(24)

But i need it to be in form of datetime so that i can use the datetime functions on it..When i use the cast or convert inside the function where i am passing this character it gives me error

"Conversion failed when converting datetime from character string."

I am done all permutatiions and combinations for this used

Set @DE = convert ( datetime, @ts,121)

Set @de = cast( @ts as datetime)

BUT ALWZ give me same error.... also when i copy the whole of the data table into some other database the error doesnt come.. i converts the character into the datetime..

I DONT understand why the Server is behaving wiered..

Hoping to get an answer soon.

With regards

Sharad

Database Developer ,

UIC

View 4 Replies View Related

Converting Varchar To Datetime

Oct 23, 2007



Hi,


I'm facing a small issue with date conversions. It would have been great if someone could help me out. I have a field in my database (SQL Server 2000) called SavDateTime of type varchar(50). I store dates in this field in the format "dd/MM/yy hh:mms". A sample date would be "23/10/2007 10:15:30 AM". Now I need to have an order by for this field, say like,


select * from sample order by SavDateTime desc


When I execute this query I get an error saying "The conversion of a char data type to a datetime data type resulted in an out-of-range datetime value.". I tried using the convert method also like CONVERT(DATETIME,SavDateTime,103), but the problem still exists. It would have been helpful if you could provide me with a solution to this problem.



Thanks & Regards,
Frens

View 7 Replies View Related

Converting String To Datetime

Jul 26, 2007

Hi
What's wrong about

SELECT SUM(CASE WHEN [PO Date] BETWEEN CONVERT(Datetime, @FY + '/04/01')
AND CONVERT(Datetime, @FY -1 + '/03/31') THEN Quantity ELSE 0 END) AS Expr1,
[Item No_]
FROM table A

View 7 Replies View Related

Converting Integers To DateTime

Jun 12, 2007

It seems I am facing again an unsurmountable problem It should be so simple but one has to spend hours researching how to handle it. The MSDN help on this subject is increadibly obscure.



I have input parameters @months int, @days int, @years int in a stored procedure.



All I want to do is to get a DateTime variable out of them.



DECLARE @dated DateTime.



Thus I want @dated to be set to a DateTime value with month = @months, day = @days and year = @years. The MSDN help says that no CAST should be used since the conversion from int to DateTime should be implicit!!



No examples are given. They seem to show how to CAST or CONVERT varchar to DateTime. Shall I first convert my int to varchar?



It is rudiculous. I've tried dozens of variants. Please help.



Thanks.

View 10 Replies View Related

Converting Datetime Formats And Layouts?

Apr 30, 2007

Opening DimTime table of AdventureWorksDW sample database in MS SQL Server Management Studio shows me values in FullDateAlternatKey like

View 3 Replies View Related

Error Converting Datetime To String.

Jun 6, 2008

I have a dropdown list thats boudn to a SqlDataSource.  The DataSource looks like this:
  <asp:SqlDataSource ID="dsProgramList" runat="server" ConnectionString="<%$ ConnectionStrings:csData %>"
SelectCommand="SELECT DISTINCT [Program_Name] +','+ [Begin_Date] AS NAMEandDATE, [Course_ID], [LOC] FROM [ThisTable] WHERE ([LOC] = @LOC)">
<SelectParameters> 
 
Where the dropdownlists text = NAMEandDATE and its value = Course_ID
When I select the LOC from the LOCdropdownlist, the dropdownlist in question updates, and an error "Erro converting datetime from character string" happens?
Any suggestions?

View 4 Replies View Related

Converting Datetime From Character String

Jun 28, 2004

Hi there,

I have the following code:

Dim CityTown As String = Ctype(Request.Querystring("CityTown"), String)
Dim Suburb As String = Ctype(Request.Querystring("Suburb"), String)
Dim SuburbValue As String = Ctype(Request.Querystring("Suburb"), String)
Dim Rooms As String = Ctype(Request.Querystring("Rooms"), String)
Dim Rent As String = Ctype(Request.Querystring("Rent"), String)

Dim DateToday = DateTime.Now
Dim mySQL AS String
If suburbValue = "- All -" Then
mySQL = "SELECT propListID, propListExpires, propBuildType, propRoomNumber, propRentPerWeek, propDescription, propCityTown, propSuburb FROM tblPropertyList WHERE [propCityTown]='" & CityTown & "' AND [propRentPerWeek]<= '" & Rent & "' AND [propRoomNumber]='" & Rooms & "'AND [propListExpires] >='" & DateToday & "' "


However I am having trouble getting the Date to work as part of my SQL String. I keep getting the following error:

Syntax error converting datetime from character string.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Data.SqlClient.SqlException: Syntax error converting datetime from character string.

Source Error:


Line 30: MyDA = New SqlDataAdapter (mySQL, myConn)
Line 31: myDS = New DataSet()
Line 32: myDA.Fill(MyDS)
Line 33:
Line 34: dlPropertyListing.Datasource = MyDS.Tables(0)


Source File: K:detailsdetailspropertylisting.aspx Line: 32


Any ideas how to resolve this?? I do not want to use Parameters in my statement.

Thanks in advance,

TCM

View 3 Replies View Related

Converting DateTime To SqlDateTime Format

Mar 30, 2006

Hi,
I have a function that generates a range of DateTimes, which I then cast to SqlDateTime to compare with SqlDateTime values in a database.
The problem is my converted DateTimes come out in this type of format "6/2/2006 12:00:00 AM"
wheras my SqlDateTimes in the database are in this format "2006-01-18T00:00:00.0000000-12:00"
Any ideas how I can convert the DateTime values to SqlDateTime correctly so that I can compare them?  As I said I tried creating a new SqlDateTime object with the DateTime value ie
DateTime dt = new DateTime("");
SqlDateTime sdt = new SqlDateTime(dt);
But that doesn't work correctly, its still not in the format that is in the database.

View 1 Replies View Related

Converting A Char Column To Datetime

Jan 24, 2002

Hello everyone, I have searched and seached for an answer to something that I know has to be simple but have been unsuccessful. I appreciate any help...

I am trying to take a char (6) column named col001 and convert it to datetime.
The column is in mmddyy format. I am using SQL 2000, but have available sql 7.0 servers if there is a difference. I expect that I have to write a cursor but have been unable to get the correct syntax. Thanks everyone

View 1 Replies View Related

Converting Character Data To DATETIME

Aug 2, 1999

For our DataWarehouse, we get several date fields from our mainframe system in a character format. When this data was loaded into SQL Server 6.5 using the CONVERT(DATETIME...) function, any dates containing 'bad' data would simply be replaced by a NULL automatically by the DBMS. We are now going to SQL 7.0, and I have found that when it hits a bad date it terminates the stored procedure, resulting with no update.

Is there a straightforward way around this? Possibly a script that will scrub the data, replacing bad data with NULLs? I'm trying to avoid writing something that will take the number of days per month and determine if it is valid.

Thanks

Michael

View 1 Replies View Related

Converting Integer To Datetime Format

May 2, 2006

Hello Everyone,

I need help with conversion type. I'm using Visual Basic 6.0 as my frontend and SQL Server 2000 as my backend. There has been existing data in the database. I would like to know how to convert an integer to datetime format. For example:

This is the actual value from the database.

1087912290
1087912327

I'd like to know how to convert it datetime format.

Any help would be greatly appreciated.

Thanks,

Dennis

View 14 Replies View Related

Building A String And Converting To DATETIME

Jul 9, 2007

Hi all, first time post so go easy.

I have been trying to find a way of creating a datetime comprised of getdate() and a time that i specify. I am trying to do this as shown below:

Declare @Test datetime
Declare @Test1 Datetime

Set @Test = getdate()

SET @Test1 = CONVERT(datetime, datepart(y, @Test) + datepart(m, @Test)+ datepart(d, @Test)+' 16:30:00',120)

So, i am building a string using datepart and then adding the time at the end. The 120 after the final comma is to define the style (as i am sure you will all know anyway).

When i run this i get the following error:

Msg 245, Level 16, State 1, Line 35
Syntax error converting the varchar value ' 16:30:00' to a column of data type int.

If i take out the colons it runs but brings back the wrong date, the whole date seems to be dependant on the time part at the end.

I am sure this is a really simple problem and i am sorry if i am wasting you time but its late and i just cant see it. Any help would be fantastic.

View 2 Replies View Related

Converting Datetime From Character String

Dec 2, 2004

Can anyone tell me what this error message means and how I can correct it on my statement:
Code:

Server: Msg 241, Level 16, State 1, Line 1Syntax error converting datetime from character string.

Here's my query statement:
Code:

SELECT animalid AS "Animal ID", name AS "Name", categoryid AS "Category ID", DATENAME(MONTH, dateBorn) + ' ' + DATENAME(DAY, dateBorn) + ', ' + DATENAME(YEAR, dateBorn) AS "Date of Birth"FROM animalWHERE categoryid = 'Cat' AND dateBorn = 'May%'

I know it has something to do with: dateBorn = 'May%' because when I took out Quote: AND dateBorn = 'May%' I get results, but I need to narrow it down to list the cats born in May.

View 6 Replies View Related

Problem Converting CHAR To DATETIME

Jan 22, 2007

hello all, I am having a problem calculating the difference, in days, between two dates, STARTDATE and ENDDATE. The data is stored in the database as char(8), formatted YYYYMMDD. "Null" values are stored as '00000000'. When I try to use DATEDIFF an exception is thrown: "the conversion of a char data type to a datetime data type resulted in an out-of-range datetime value" How can I fix this, and a get a result even if STARTDATE or ENDDATE is '00000000'? Changing the format of the stored data is not an option. Thanks for any assistance. Mike CREATE TABLE dbo.DATETIME1 (ID1 int,STARTDATE char(8),ENDDATE char(8))INSERT into DATETIME1 (ID1, STARTDATE, ENDDATE)VALUES (1, '20070105', '20070108')INSERT into DATETIME1 (ID1, STARTDATE, ENDDATE)VALUES (2, '20070105', '00000000')Select * from DATETIME1Select DATEDIFF(d, STARTDATE, Convert(datetime,ENDDATE) ) as Difference from DATETIME1 WHERE ID1 = 1

View 5 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved