Showing posts with label date. Show all posts
Showing posts with label date. Show all posts

Wednesday, March 7, 2012

copying a row to new table - not copying one date column

I have two tables, a PendingOrder table and a CompletedOrder table. I have a stored procedure that moves an order from the pending table to the completed table, and I am having an issue with copying over a date field (the date the order was created). Here is what I have....

The store procedure takes in the following:
@.PendOrderKey INT,
@.Status INT

Here is my insert statement:

INSERT INTO CustOrder (CustAddrKey, UserKey, ContactName, ContactPhone, CustPONo, VendLocalSupplierKey, Notes, Status, OrderTypeKey, CreatedDate, ModifiedDate)
SELECT CustAddrKey, UserKey, ContactName, ContactPhone, CustPONo, VendLocalSupplierKey, Notes, @.Status, OrderTypeKey, CreatedDate, GETDATE()
FROM PendCustOrder
WHERE PendOrderKey = @.PendOrderKey

For some reason, when I run this on an order, instead of taking the value of "CreatedDate" from the pending order table and inserting it into the CreatedDate field of the completed order table, it inserts the current date and time into the completed order table. The "CreatedDate" field in the completed orders table does not allow nulls and has no default value, so I'm confused as to why it's inserting the current date/time. Any help would be greatly appreciated. Thanks!!

Maguidhir:

Check and see if the target table has a trigger that sets the "CreatedDate" field when a new record is inserted into the table.


Dave

|||Thank you so much! It does have a trigger that sets the CreatedDate=GetDate()!

Saturday, February 25, 2012

CopyFile in DTS ActiveX Script Task

I am trying to copy a file and giving it a name with a date behind it. Belo
w
is my code I'm using in my DTS ActiveX Script Task. I'm getting a "File Not
Found" message on Line 25 (I marked it below). Can someone see the problem
with my code'
Dim NYear
Dim NMonth
Dim NDate
NYear = Year(Date)
NMonth = Month(Date)
NDate = CStr(NYear) + CStr(NMonth)
Dim oFSO
Dim sSourceFile
Dim sDestinationFile
Set oFSO = CreateObject("Scripting.FileSystemObject")
sSourceFile =
" \\wstlfp02\ebs$\SQLDataAccess\WPE\PandGI
nvoicesToMCFA\PGInvoiceDetailYYYYMM
"
sDestinationFile =
" \\wstlfp02\ebs$\SQLDataAccess\WPE\PandGI
nvoicesToMCFA\PGInvoiceDetail" +
"_RunDate_" + NDate
oFSO.CopyFile sSourceFile, sDestinationFile '***(This is Line 25)***
' Clean Up
Set oFSO = Nothing
Main = DTSTaskExecResult_SuccessHi
I assume you have tried outputting the file names in a MsgBox and validated
that they are correct? http://www.sqldts.com/default.aspx?292 has an example
of using the filesystem object to copy a file, and
http://www.sqldts.com/default.aspx?200 has an example of using the date as
part of a filename.
Make sure that the account that you are running this has permissions to the
share, it may be worth getting it working with a local drive first.
John
"atchleykl" wrote:

> I am trying to copy a file and giving it a name with a date behind it. Be
low
> is my code I'm using in my DTS ActiveX Script Task. I'm getting a "File N
ot
> Found" message on Line 25 (I marked it below). Can someone see the proble
m
> with my code'
> Dim NYear
> Dim NMonth
> Dim NDate
> NYear = Year(Date)
> NMonth = Month(Date)
> NDate = CStr(NYear) + CStr(NMonth)
> Dim oFSO
> Dim sSourceFile
> Dim sDestinationFile
> Set oFSO = CreateObject("Scripting.FileSystemObject")
> sSourceFile =
> " \\wstlfp02\ebs$\SQLDataAccess\WPE\PandGI
nvoicesToMCFA\PGInvoiceDetailYYYY
MM"
> sDestinationFile =
> " \\wstlfp02\ebs$\SQLDataAccess\WPE\PandGI
nvoicesToMCFA\PGInvoiceDetail" +
> "_RunDate_" + NDate
> oFSO.CopyFile sSourceFile, sDestinationFile '***(This is Line 25)***
> ' Clean Up
> Set oFSO = Nothing
> Main = DTSTaskExecResult_Success
>