Saturday, February 25, 2012

Newbie - Data Conversion?

Hi everyone... sorry, but I'm really new at this! I'm trying to make a table out of an imported Excel file (which is automatically generated as an all-text data type). I wrote a query that takes this excel file and puts it into the format we need (i.e., appropriate column headers, removing "garbage" characters and spaces). Is there any way to format the data going into the table by a specified datatype?

Sorry if this is simplistic or wasting your time, but I'm really stumped :o. However, keep in mind that I started learning SQL this morning and I've already gotten this far :).How did you get EXCEL in to a table?

DTS, I imagine.

I would have it set up to a staging table where all the columns are varchar..then you can do whatever you want...

what code did you write?|||Sorry I didn't make it clear :). I import the Excel file into my Access database, and manipulate it from there. The Query-Wizard was pretty retarded, so I decided to just do the SQL myself.|||INSERT...
SELECT cast(<source_field1> as <data_type>)|||I thought I would include a snippet of my crappy code :). YES, I realize you typically only have to put brackets with buzzwords and spaces, but it's just something I do.

Where exactly would I put the CAST() command at?

SELECT [Sheet1].[Field15] AS Location, [Sheet1].[Field2] AS EquipID, [Sheet1].[Field3] AS Asset, [Sheet1].[Field4] AS [Date], [Sheet1].[Field5] AS Eracent, [Sheet1].[Field6] AS [Login ID], [Sheet1].[Field7] AS RAM, [Sheet1].[Field8] AS [O/S], [Sheet1].[Field9] AS CPU, [Sheet1].[Field10] AS [EMP ID], [Sheet1].[Field11] AS [Cost Center], [Sheet1].[Field12] AS [First Name], [Sheet1].[Field13] AS [Last Name], [Sheet1].[Field14] AS Phone, [Sheet1].[Field16] AS Div, [Sheet1].[Field17] AS Dept INTO FormattedReport
FROM Sheet1;|||SELECT cast([Sheet1].[Field15] as varchar(35)) AS Location, ... , etc.|||Errrggg! I got a "Missing Operator" syntax error with the first CAST()! Did I type something incorrectly?

SELECT cast([Sheet1].[Field15] as VARCHAR(35)) AS Location, cast([Sheet1].[Field2] as INT) AS EquipID, cast([Sheet1].[Field3] as INT) AS Asset, (so on and so forth)

No comments:

Post a Comment