Solved

DTS Date Format

Posted on 2002-04-04
4
365 Views
Last Modified: 2013-11-30
I'm trying to do two things:  1) if a date is 1/1/1900 then make it blank. 2) if a date isn't 1/1/1900 then put it in the format yyyyMMdd (20020403).  My problem is the format part I can put it in a short or long date format but I can't get it in the format that I'm wanting.

Function Main()
  if DTSSource("IndividualTermDateDep") = "1/1/1900" then
     DTSDestination("IndividualTermDateDep") = ""
     Main = DTSTransformStat_OK
  else
     DTSDestination("IndividualTermDateDep") = FormatDateTime(DTSSource("IndividualTermDateDep"),  2)
     Main = DTSTransformStat_OK
  end if
End Function  


Thanks
yunginv
0
Comment
Question by:yunginv
  • 2
  • 2
4 Comments
 
LVL 6

Expert Comment

by:curtis591
ID: 6919404
When I do these types of things I put all the data into a temporary table before I load it into master table. I can then create views and run update statements to clean the data and that makes it easier than trying to do it in the dts package.  It is also very easy to loose your script on each field when you are changing the package.
0
 

Author Comment

by:yunginv
ID: 6921020
I understand that position but I'd really like to know how to do it in code instead of creating a temp table and then loading it into another table.  Surely there is a way to format the date.  

By the way I've tried using the VB code format(date, "yyyyMMdd") and got an error as well.

yunginv
0
 
LVL 6

Accepted Solution

by:
curtis591 earned 200 total points
ID: 6921061
You should be able to do it with the mid function I think.  

How about this does this work?  Example format
mmddyyyy
01012002


DTSDestination("IndividualTermDateDep") = mid(DTSSource("IndividualTermDateDep"),5,4)+mid(DTSSource("IndividualTermDateDep"),1,4)
0
 

Author Comment

by:yunginv
ID: 6921075
I didn't even think of using the MID statment.  Thanks.

I still think there has to be a format statement that works but this is as good.

Again Thanks
yunginv
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
SQL Server / Update DB? 22 36
TSQL convert date to string 4 34
TSQL XML Namespaces 7 22
SQL 2012 clustering 9 11
Nowadays, some of developer are too much worried about data. Who is using data, who is updating it etc. etc. Because, data is more costlier in term of money and information. So security of data is focusing concern in days. Lets' understand the Au…
For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question