SSIS Deriving Dt_str To Dt_dbtimestamp Including Milliseconds
Dec 27, 2007
Hi, I am trying to derive a column from:
mm/dd/yyyy hh:mms.fff to dt_dbtimestamp as:
(dt_dbtimestamp)(colum_name,1, 23) when I include the period and three digits for milliseconds the package fails if I leave it out it is successfull. I need to include milliseconds for my datawarehouse project. I tried many different ways and always with failure
01/23/2007 12:23:15.234 is the date(example) derived: (dt_dbtimestamp)(column_name,1,23) fails
01/23/2007 12:23:15.234 is the date(example) derived: (dt_dbtimestamp)(column_name,1,19) succeeds
Thanks
View 9 Replies
ADVERTISEMENT
May 22, 2007
I've been working on a project to ensure that accross our entire data warehouse everything is at the same accuracy level as far as time - migrating everything to use the full hh:mis.mmm. Some places were using hh:mis:mmm (colon instead of decimal point) and many places not using milliseconds.
The SQL server portion went essentially without issue - however SSIS is not cooperating. For example I have data I am importing from a file that is in format: hh:mis (no milliseconds) that I need to compare to data from SQL (now containing full milliseconds) - matching on time ranges. Previously this was done by converting both to the "database time" datatype in SSIS and comparing. Now when converting the cTime to database time SSIS fails and complains "The value could not be converted because of a potential loss of data".
I don't want to lop off the milliseconds becuase that could create rounding errors.
I don't like it but the only option I can think of is keeping everything in string and comparing the strings... then I run into the issue of making sure to convert all sources of data into the exact same hh:mis:mmm format in text.
Is there an easier way? I know some people use "milliseconds since midnight" and so forth but that would require major reworking of the data warehouse and many packages.
View 7 Replies
View Related
Jun 16, 2006
Hello
As a beginner I have created some Packages to import Data to SQL Server.
The Packages are running well.
I have created a Task to run the Package on a SQL SERVER 2005 Express. The Task starts.
Then a Execute Package Wizard Picture appears on the Screen.
I have mannually to select the Connection Manager and the Connection String.
After the selection the Task runs without any Problem.
Now I like to get the Task to run without any manual intervention.
I was looking in Internet but could not find a solution.
Can someone give me a hint how to get the Task working without intervention?
Thanks for an early answer.
Regards
Chaepp
View 3 Replies
View Related
May 22, 2008
Hello everyone,
This is a new level of complexity for me..
The Boss wants..
1. To control an SSIS package , start, check status, and emergency stop + rollback a package from a web page. Does anyone know of an example or good articles to start with.
2. I have one of the iterations of the data invoke and use a COM object (third party) It will value the items and change a field.
I can always do #2 as a second step but I need all the help I can get on #1.
Thank you,
View 1 Replies
View Related
May 2, 2006
I have an int column in table and need to convert DT_DBTIMESTAMP column to int in Conditional_Split transformation editor.
SPOL_ProcessDate > CAST(CONVERT(varchar, DATEADD(day, 5, GETDATE()),112) AS int);
Does any know how to convert this is Conditional_Split transformation?
Thanks in advance.
View 2 Replies
View Related
Nov 13, 2007
Hello All
I want to creat a colunm from two colunms in a specific format
COL1 COL2 COL3
123456 01-10-2007 12070001 ( 12: From First two digit of Col1, 07 from the year of colunm2 and 0001: if combination 1207 is first else increment)
125647 01-11-2005 12050001
126756 12-25-2007 12070002 (* here since combination of 1207 is repeating it gets increment to 0002)
Can somebody help me please
View 8 Replies
View Related
May 15, 2008
(DT_DBTIMESTAMP)(TRIM("01-01-" + (DT_WSTR,4)(Year)))
Hello I want to know what is the significance of putting DT_DBTIMESTAMP and DT_WSTR in the above line,
Thanks
View 2 Replies
View Related
Feb 7, 2008
I am new to SSIS technology. Trying to import data from an Excel file to a SQL Database. This error is not letting me.
TITLE: Package Validation Error
------------------------------
Package Validation Error
------------------------------
ADDITIONAL INFORMATION:
Error at Data Flow Task [SQL Server Destination [14]]: The column "Opened On" can't be inserted because the conversion between types DT_DATE and DT_DBTIMESTAMP is not supported.
Error at Data Flow Task [DTS.Pipeline]: "component "SQL Server Destination" (14)" failed validation and returned validation status "VS_ISBROKEN".
Error at Data Flow Task [DTS.Pipeline]: One or more component failed validation.
Error at Data Flow Task: There were errors during task validation.
I tried using Data Conversion and Derived column, still this error prevails. Any help ????
View 8 Replies
View Related
Oct 25, 2005
My application is to capture employee locations.Whenever an employee arrives at a location (whether it is arriving forwork, or at one of the company's other sites) they scan the barcode ontheir employee badge. This writes a record to the tblTSCollected table(DDL and dummy data below).The application needs to be able to display to staff in a control roomthe CURRENT location of each employee.[color=blue]>From the data I've provided, this would be:[/color]EMPLOYEE ID LOCATION CODE963 VB002964 VB003966 VB003968 VB004977 VB001982 VB001Note that, for example, Employee 963 had formerly been at VB001 but wasmore recently logged in at VB002, so therefore the application is notconcerned with the earlier record.What would also be particularly useful would be the NUMBER of staff ateach location - viz.LOCATION CODE NUM STAFFVB001 2VB002 1VB003 2VB004 1Can anyone help?Many thanks in advanceEdwardNOTES ON DDL:THE BARCODE IS CAPTURED BECAUSE THE COMPANY MAY RE-USE BARCODE NUMBERS(WHICH IS DERIVED FROM THE EMPLOYEE PIN), SO THEREFORE THE BARCODECANNOT BE RELIED UPON TO BE UNIQUE.THE COLUMN fldRuleAppliedID IS NULL BECAUSE THAT PARTICULAR ROW HAS NOTBEEN PROCESSED. THERE ARE BUSINESS RULES CONCERNING EMPLOYEE HOURSWHICH OPERATE ON THIS DATA. ONCE A ROW HAS BEEN PROCESSED FORUPLOADING TO THE PAYROLL APPLICATION, THE fldRuleAppliedID COLUMN WILLCONTAIN A VALUE. IN THE PRODUCTION SYSTEM, THEREFORE, ANY SQL ASREQUESTED ABOVE WILL CONTAIN IN ITS WHERE CLAUSE (fldRuleAppliedID IsNULL)if exists (select * from dbo.sysobjects where id =object_id(N'[dbo].[tblTSCollected]') and OBJECTPROPERTY(id,N'IsUserTable') = 1)drop table [dbo].[tblTSCollected]GOCREATE TABLE [dbo].[tblTSCollected] ([fldCollectedID] [int] IDENTITY (1, 1) NOT NULL ,[fldEmployeeID] [int] NULL ,[fldLocationCode] [varchar] (50) COLLATE SQL_Latin1_General_CP1_CI_ASNULL ,[fldTimeStamp] [datetime] NULL ,[fldRuleAppliedID] [int] NULL ,[fldBarCode] [varchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL) ON [PRIMARY]GOINSERT INTO dbo.tblTSCollected(fldEmployeeID,fldLocationCode,fldTimeStamp,fldBarCode)VALUES (963, 'VB001', '2005-10-18 11:59:27.383', 45480)INSERT INTO dbo.tblTSCollected(fldEmployeeID,fldLocationCode,fldTimeStamp,fldBarCode)VALUES (963, 'VB002', '2005-10-18 12:06:17.833', 45480)INSERT INTO dbo.tblTSCollected(fldEmployeeID,fldLocationCode,fldTimeStamp,fldBarCode)VALUES (964, 'VB001', '2005-10-18 12:56:20.690', 45481)INSERT INTO dbo.tblTSCollected(fldEmployeeID,fldLocationCode,fldTimeStamp,fldBarCode)VALUES (964, 'VB002', '2005-10-18 15:30:35.117', 45481)INSERT INTO dbo.tblTSCollected(fldEmployeeID,fldLocationCode,fldTimeStamp,fldBarCode)VALUES (964, 'VB003', '2005-10-18 16:05:05.880', 45481)INSERT INTO dbo.tblTSCollected(fldEmployeeID,fldLocationCode,fldTimeStamp,fldBarCode)VALUES (966, 'VB001', '2005-10-18 11:52:28.307', 97678)INSERT INTO dbo.tblTSCollected(fldEmployeeID,fldLocationCode,fldTimeStamp,fldBarCode)VALUES (966, 'VB002', '2005-10-18 13:59:34.807', 97678)INSERT INTO dbo.tblTSCollected(fldEmployeeID,fldLocationCode,fldTimeStamp,fldBarCode)VALUES (966, 'VB001', '2005-10-18 14:04:55.820', 97678)INSERT INTO dbo.tblTSCollected(fldEmployeeID,fldLocationCode,fldTimeStamp,fldBarCode)VALUES (966, 'VB003', '2005-10-18 16:10:01.943', 97678)INSERT INTO dbo.tblTSCollected(fldEmployeeID,fldLocationCode,fldTimeStamp,fldBarCode)VALUES (968, 'VB001', '2005-10-18 11:59:34.307', 98374)INSERT INTO dbo.tblTSCollected(fldEmployeeID,fldLocationCode,fldTimeStamp,fldBarCode)VALUES (968, 'VB002', '2005-10-18 12:04:56.037', 98374)INSERT INTO dbo.tblTSCollected(fldEmployeeID,fldLocationCode,fldTimeStamp,fldBarCode)VALUES (968, 'VB004', '2005-10-18 12:10:02.723', 98374)INSERT INTO dbo.tblTSCollected(fldEmployeeID,fldLocationCode,fldTimeStamp,fldBarCode)VALUES (977, 'VB001', '2005-10-18 12:05:06.630', 96879)INSERT INTO dbo.tblTSCollected(fldEmployeeID,fldLocationCode,fldTimeStamp,fldBarCode)VALUES (982, 'VB001', '2005-10-18 12:06:13.787', 96697)
View 4 Replies
View Related
Nov 21, 2007
hi,
i have to derive a column from an existing column in my data source with a data type of DATE.
to illustrate my point lets assume that:
i have dt00 as my current column with its data type of date and now i have to create another column dt01 with data type int.
i need to format the date from dt00 to the following format yyyyMMddhhmm, where
yyyy - year
MM- moth in two digits (e.g: 03, 12)
dd - days in two digits (e.g: 03, 12)
hh - hours in two digits (e.g: 03, 12)
mm - minutes in two digits (e.g: 03, 12)
and allocate this value to this new column dt01.
could someone give me some clue on how to do this using the SCRIPT TASK?
many thanks,
nicolas
View 6 Replies
View Related
May 16, 2006
Anyone know the origin of sql 2005's datatype naming convention or even why SSIS has defined its own special data types? (Before SSIS I had never seem types like DT_UI1 except in programming languages.)
TIA,
barker
View 1 Replies
View Related
May 15, 2006
Okay, this is probably my own stupidity but here goes. I am trying to make a very rudimentary package. I've got a data flow that has a flat file source. This source has fields delimited by the | symbol. I give the fields in the flat file source names. The first field is always exactly 1 character. When I use the advanced editor to look at the fields' properties, I see the first field, called ProductLine, is considered to be of SSIS internal data type DT_STR with a length of 50. I change the 50 to 1 because that is as long as that field is.
No matter what I do, when I close the advanced editor and then open it again, the field length for ProductLine is again set to 50. The field is 1 long, not 50 long. How can I make the setting of 1 be retained? Nothing I do changes it. What is the point of allowing the length to be editable if the edit is not retained?
Thanks in advance,
SW
View 4 Replies
View Related
Apr 26, 2007
I have a OLE DB Source going to a flat file destination. My source is a sql variable with "select * from tablename" which have varchar datatypes. Yet I'm getting trailing spaces at the end of some of my columns (for instance, my address column).
I've checked the data by doing a "select Max(Len(address)) from tablename" and the max is only like 34 chars, yet each of them have 100 chars total.
Taking a look at my flat file connection, the outputColumnWidth is 100, and datatype is string [DT_STR]. Am I crazy? What's the problem here? Is the DT_STR datatype the equivalent of char, and not varchar?
Any help, of course, will be appreciated.
View 8 Replies
View Related
May 28, 2008
Can anyone tell me how to convert a string variable to boolean
Ihave a variable named VarLoc which is string datatype
In expression I want to give condition like
VarLoc == "1234"?False:True
its giving error because of converting string datatype to boolean.
Please help.
Thank You
View 3 Replies
View Related
Mar 30, 2007
Our shop's DTS packages usually use ActiveX scripts to dynamically name vendor text file inputs by date (YYYYMMDD), which we load Monday through Friday to our databases. For our 2005 server I am trying to dynamically name a 'flat file source' filename in SSIS as described in the article at the url http://www.mssqltips.com/tip.asp?tip=1084.
I am writing the expression (DT_STR, 4,1252) YEAR(DATEADD( "dd",0, getdate() ) to create a variable named FileName to capture today's 4 character year. If I could get a good preview of this value I would concatenate the month and day strings to it and use the resultant variable as part of the fully qualifeid name.
For the variable I've marked the 'evaluateasexpression' true and put the value type as str. But when I preview this expression I get the error message, 'expression has the result type of DT_STR which can not be converted to a supported type.'
What supported type? Does anyone see what the problem is?
View 9 Replies
View Related
Dec 18, 2007
Hi,
Having problem with OLE-DB connection to informix.
Created a flat file has two columns and 2 row:
1|a
2|b
tried to load it to a informix table:
create table t
( c1 int,
c2 char
);
2 rows inserted, but only column c1 got data.
Changed c2 from char to varchar then ok.
thanks for any help.
gg
View 17 Replies
View Related
Mar 27, 2008
Hello, I understand that we should use SSMS -> Server Properties -> Memory to put a cap on the SQL server memory usage, therefore it gives some space memory for OS, this is based on the fact if the max memory is not specified, SQL will use whatever available memory and eventually crash the system.
My question is that when a server has SSIS and SSAS services installed along with the SQL service. Would the max memory setting covers the SSIS and SSAS memory usage, or the SSIS and SSAS has to shared the memory with OS?
Thanks,
fshguo.
View 1 Replies
View Related
Oct 9, 2006
The Lookup Transformation fails to match this datatype when full caching is enabled. When partial caching is activated (Edit > Advanced, Enable Memory Restrictions > Enable Caching) the lookup works.
This appears to be a bug to me.
View 4 Replies
View Related
Sep 16, 2006
Hi all I am trying to convert the string "(null)" in the [PASSWORD] column of my table to an actual NULL value. I have tried to use two different forms of a conditional operator to achieve this end. However I am getting the below errors both can be summed up with the following statement.
DT_STR operand cannot be used with the conditional operation. The expression directly below however is using a type DT_I4 in the conditional clause as this is what FINDSTRING returns. Hence the equivalencey test to the literal integer 0. So I must say I am somewhat confused by this. Does anyone know why neither of the below statements are working?
Also is there an easy way to accomplish what I am trying to do - convert the string "(null)" in the [PASSWORD] column of my table to an actual NULL value?
FINDSTRING([PASSWORD], "(null)", 1) == 0 ? [PASSWORD] : NULL(DT_STR, 255, 1252)
Error at Administrator Data Flow Task [Derived Column [1985]]: For operands of the conditional operator, the data type DT_STR is supported only for input columns and cast operations. The expression "FINDSTRING(PASSWORD,"(null)",1) == 0 ? PASSWORD : NULL(DT_STR,255,1252)" has a DT_STR operand that is not an input column or the result of a cast, and cannot be used with the conditional operation. To perform this operation, the operand needs to be explicitly cast with a cast operator.
LOWER( TRIM( [PASSWORD] ) ) != "(null)" ? [PASSWORD] : NULL(DT_STR, 255, 1252)
Error at Administrator Data Flow Task [Derived Column [1985]]: For operands of the conditional operator, the data type DT_STR is supported only for input columns and cast operations. The expression "LOWER(TRIM(PASSWORD)) != "(null)" ? PASSWORD : NULL(DT_STR,255,1252)" has a DT_STR operand that is not an input column or the result of a cast, and cannot be used with the conditional operation. To perform this operation, the operand needs to be explicitly cast with a cast operator.
View 4 Replies
View Related
Mar 7, 2002
Hi
Does anybody know while loading data from text file into sql server, how
can we ignore milliseconds.
regards
JK
View 1 Replies
View Related
May 8, 2008
I have got data like this below in effective date column
2008-08-05 19:18:13.000
2008-08-05 19:17:10.000
Expected output:
2008-08-05 19:17:10
I need to truncate the milliseconds and insert the same into datetime column.
I tried as below
select convert(datetime,substring(convert(varchar,getdate(),20),1,20))
Thanks in advance
View 9 Replies
View Related
Nov 19, 2004
Hi,
i am trying to add milliseconds to a time. For example if i have a time of 01:01:05:000 and i want to add 0.297 milliseconds to it i use the following simplified query
SELECT CONVERT(nvarchar(20), DATEADD(ms, 0.297, '00:01:05:000'), 14) AS Expr1
However instead of getting 01:01:05:0.297 i get 01:01:05:000. Can somebody please tell me what i am doing wrong.
Thanks in advance.
View 4 Replies
View Related
Nov 19, 2004
Hi,
i am trying to add milliseconds to a time. For example if i have a time of 01:01:05:000 and i want to add 0.297 milliseconds to it i use the following simplified query
Code:
SELECT CONVERT(nvarchar(20), DATEADD(ms, 0.297, '00:01:05:000'), 14) AS Expr1
However instead of getting 01:01:05:0.297 i get 01:01:05:000. Can somebody please tell me what i am doing wrong.
Thanks in advance.
View 2 Replies
View Related
Feb 9, 2015
why the results I receiving for Seconds is different? I get the same MS results.
Microsoft SQL Server 2008 R2 (SP2) - 10.50.4000.0 (X64)
Jun 28 2012 08:36:30
Copyright (c) Microsoft Corporation
Standard Edition (64-bit) on Windows NT 6.1 <X64> (Build 7601: Service Pack 1) (Hypervisor)
--Returns 1 second
SELECT RunTime_SEC = DATEDIFF(SECOND, '2015-02-09 13:34:13.977', '2015-02-09 13:34:14.230')
,RunTime_MS = DATEDIFF(ms, '2015-02-09 13:34:13.977', '2015-02-09 13:34:14.230')
--Returns 0 second
SELECT RunTime_SEC = DATEDIFF(SECOND, '2015-02-09 13:30:30.147', '2015-02-09 13:30:30.400')
,RunTime_MS = DATEDIFF(ms, '2015-02-09 13:30:30.147', '2015-02-09 13:30:30.400')
View 6 Replies
View Related
Mar 27, 2006
hi ppls..
we have sql server 2000 EM. we received daily xml files and we insert into our database.there is one column Date_T having data type datetime.till date we recieved this records from xml as '03/23/2004 12:23:34:956' but due to some duplicate isssue we now want to modified this column to recieve as milliseconds like '03/23/2004 12:23:34:956232' now my point is wheather sql server handle this kind of milliseconds..please help me out as early as possible..
T.I.A
Papillon
View 9 Replies
View Related
Oct 16, 2006
Hi!
I have the difference between two dates in milliseconds. I want to convert this difference to the format hh:mm:ss.mmm, without the date. So, if the difference is bigger then one day, I would like to show it like this, for example: 36:25:14.047
How can I do this?
Thank you!
View 5 Replies
View Related
Nov 5, 2007
Hi,
I am trying to access a date column up to millisecond precession. So I cast date to as follows:
Code BlockCONVERT(varchar(23),CREATE_DATE,121)
I get millisecond part as a result of query but its 000?.
View 5 Replies
View Related
Aug 25, 2006
Hi,
I tried entering this value "8/24/2006 1:35:00.127 PM" with 127 as the milliseconds in a datetime field, but encountered error saying inconsistent datatype ...
Anyone knows how to store datetime value with milliseconds in the SQL database?
Thanks
View 13 Replies
View Related
Jul 20, 2005
Hello all.I am attempting to insert a row into a table with a datetime column:When the insert statement contains a value for the millisecond portionof the data time column: ie. {ts '2003-11-05 12:02:43:2960'}I get 'Syntax error converting datetime from string'When I insert a value like: {ts '2003-11-05 12:02:43'}with no millisecond value it succeeds.Any help would be appreciated.Thanks
View 5 Replies
View Related
Jul 4, 2015
I'm trying to save a datetime value from vb.net to a sql server.I'm using this code: Dim dt As DateTime = DateTime.Now.ToString("dd/MM/yyyy HH:mm:ss")
After I save this value to Database.But on sql server management studio , I see that the field's value still has the milliseconds .
View 14 Replies
View Related
Dec 1, 2015
why does select @@lock_timeout return -1. Shouldn't this return lock timeout in milliseconds?
View 2 Replies
View Related
Mar 21, 2008
I want to execute a paramterized ADO insert command into a SQL Server DATETIME column without losing the milliseconds. I can accomplish this without parameters, but that isn't what I want. Any suggestions?
It is OK that DATETIME only has a resolution of 3.33 milliseconds.
See the attached code:
Code Snippet
#include <string>
#include <iostream>
#import "C:Program FilesCommon FilesSystemadomsado15.dll" rename( "EOF", "ADOEOF" )
int main( int argc, char* argv[] )
{
::CoInitialize( NULL );
try
{
ADODB::_ConnectionPtr connection;
connection.CreateInstance(__uuidof( ADODB::Connection ) );
std::string connectionString;
connectionString.append( "Provider=SQLOLEDB;" );
connectionString.append( "Data Source=HPSERV1;" ); // Choose your server/instance.
connectionString.append( "Initial Catalog=tempdb;" );
connectionString.append( "Integrated Security=SSPI;" );
connection->ConnectionTimeout = 10;
connection->Open(
_bstr_t( connectionString.c_str() ),
_bstr_t( "" ),
_bstr_t( "" ),
ADODB::adOpenUnspecified );
std::string sqlStatement;
sqlStatement = "DROP TABLE TestTable1";
try
{
connection->Execute( _bstr_t( sqlStatement.c_str() ), NULL, ADODB::adExecuteNoRecords );
}
catch( const _com_error& )
{
// Ignore errors as table probably doesn't exist.
}
sqlStatement = "CREATE TABLE TestTable1 ( ColInt INT NOT NULL PRIMARY KEY, ColDate DATETIME )";
connection->Execute( _bstr_t( sqlStatement.c_str() ), NULL, ADODB::adExecuteNoRecords );
// ====================================================================
// Works (datetime resolution is 3.33 milliseconds so rounds to .347)
sqlStatement = "INSERT INTO TestTable1 ( ColInt, ColDate ) VALUES ( 1, '2007-12-28 20:05:16.345' )";
connection->Execute( _bstr_t( sqlStatement.c_str() ), NULL, ADODB::adExecuteNoRecords );
// ====================================================================
// Works (NULL is inserted)
sqlStatement = "INSERT INTO TestTable1 ( ColInt, ColDate ) VALUES ( 2, NULL )";
connection->Execute( _bstr_t( sqlStatement.c_str() ), NULL, ADODB::adExecuteNoRecords );
// ====================================================================
// Works (datetime resolution is 3.33 milliseconds so rounds to .347)
sqlStatement = "INSERT INTO TestTable1 ( ColInt, ColDate ) VALUES ( 3, CONVERT( DATETIME, '2007-12-28 20:05:16.345' ) )";
connection->Execute( _bstr_t( sqlStatement.c_str() ), NULL, ADODB::adExecuteNoRecords );
// ====================================================================
unsigned int colInt = 3;
sqlStatement = "INSERT INTO TestTable1 ( ColInt, ColDate ) VALUES ( ?, ? )";
ADODB::_CommandPtr command;
// ====================================================================
// Fails (Operand type clash: ntext is incompatible with datetime)
colInt++;
command.CreateInstance( __uuidof( ADODB::Command ) );
command->ActiveConnection = connection;
command->CommandType = ADODB::adCmdText;
command->CommandText = _bstr_t( sqlStatement.c_str() );
command->Parameters->Append( command->CreateParameter(
_bstr_t(),
ADODB::adInteger,
ADODB::adParamInput,
4,
_variant_t( colInt ) ) );
command->Parameters->Append( command->CreateParameter(
_bstr_t(),
ADODB::adBSTR,
ADODB::adParamInput,
-1,
_bstr_t( "2005-10-25 09:10:11.012" ) ) );
try
{
command->Execute( NULL, NULL, ADODB::adCmdText );
}
catch( const _com_error& e )
{
std::cout << "Error at colInt=" << colInt << " (ADODB::adBSTR and _bstr_t):"
<< " HRESULT = " << e.Error() << ": " << e.Description() << ""
<< " SQL statement: " << command->CommandText << std::endl;
}
// ====================================================================
// Fails (Operand type clash: text is incompatible with datetime)
colInt++;
command.CreateInstance( __uuidof( ADODB::Command ) );
command->ActiveConnection = connection;
command->CommandType = ADODB::adCmdText;
command->CommandText = _bstr_t( sqlStatement.c_str() );
command->Parameters->Append( command->CreateParameter(
_bstr_t(),
ADODB::adInteger,
ADODB::adParamInput,
4,
_variant_t( colInt ) ) );
command->Parameters->Append( command->CreateParameter(
_bstr_t(),
ADODB::adChar,
ADODB::adParamInput,
-1,
_bstr_t( "2005-10-25 09:10:11.012" ) ) );
try
{
command->Execute( NULL, NULL, ADODB::adCmdText );
}
catch( const _com_error& e )
{
std::cout << "Error at colInt=" << colInt << " (ADODB::adChar and _bstr_t):"
<< " HRESULT = " << e.Error() << ": " << e.Description() << ""
<< " SQL statement: " << command->CommandText << std::endl;
}
// ====================================================================
// Fails (A datetime is inserted to table but milliseconds are zeroed)
colInt++;
::SYSTEMTIME sysNow;
::GetSystemTime( &sysNow );
double myTime;
::SystemTimeToVariantTime( &sysNow, &myTime );
// SystemTimeToVariantTime strips milliseconds, so we'll add some more
// back in as we're testing insert of milliseconds.
double desiredMilliseconds = 456;
myTime += desiredMilliseconds / 24.0 / 3600.0 / 1000.0;
command.CreateInstance( __uuidof( ADODB::Command ) );
command->ActiveConnection = connection;
command->CommandType = ADODB::adCmdText;
command->CommandText = _bstr_t( sqlStatement.c_str() );
command->Parameters->Append( command->CreateParameter(
_bstr_t(),
ADODB::adInteger,
ADODB::adParamInput,
4,
_variant_t( colInt ) ) );
command->Parameters->Append( command->CreateParameter(
_bstr_t(),
ADODB::adDate,
ADODB::adParamInput,
-1,
_variant_t( myTime, VT_DATE ) ) );
try
{
command->Execute( NULL, NULL, ADODB::adCmdText );
}
catch( const _com_error& e )
{
std::cout << "Error at colInt=" << colInt << " (ADODB::adDate and _variant_t VT_DATE):"
<< " HRESULT = " << e.Error() << ": " << e.Description() << ""
<< " SQL statement: " << command->CommandText << std::endl;
}
}
catch ( _com_error& e )
{
std::cout << "Unexpected error: "
<< e.Description() << std::endl;
}
return 0;
}
View 3 Replies
View Related
Aug 9, 2006
I am writing a report that Queries a SQL DB using 'SQL Server Business Intelligence Development Studio'. I have a field in the DB called duration and it is in milliseconds. I am trying to find an easy way to convert the format from Milliseconds to HH:MM:SS.Nearest I can get is the following for the field:
=Int( ((Fields! DURATION.Value/1000) / 60) / 60) & ":" & Int(((((Fields!DURATION.Value/1000) / 60) / 60) - Int(((Fields!DURATION.Value/1000) / 60) / 60)) * 60)
The output is in HH:MM. One issue with this is if the MM is say :03, it prints as :3. I lose the leading 0 so 9:03 (9hrs and 3 minutes) prints as 9:3. Where as 9:30 (9 hrs and 30 minutes) prints as 9:30 as it should.
View 6 Replies
View Related