Solved

How to create a SQL Server Table using CSV text file

Posted on 1998-07-30
3
137 Views
Last Modified: 2010-05-03
How can i create a table using CSV text file specification
I have a CSV file a I want to use it to create a table in SQL Server. The file has variable number of columns in each line (example: 1'st line = 12 columns, 12'th line = 14 columns).
0
Comment
Question by:labrego
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 9

Expert Comment

by:cymbolic
ID: 1467289
Are you interested in creatng a general purpose program to be used in an unattended mode on a repetitive basis, or is this just a one time special conversion?  

Anyway, if you ship me a small part of the front of your file, I'll take a look and see if I can whip out a small routine from the megs of VB/Basic code under my belt here at cymbolic@aol.com.

Just attach it to a note with enough specific information so I can get the job done.
0
 
LVL 1

Expert Comment

by:bharris1
ID: 1467290
I think you could use the Distributed Managment Objects(SQL-DMO) that should be on the SQL Server CD to create these.  I know a guy who wrote code that creates tables and stored procs based on class design.  He used SQL-DMO and found it to be pretty easy and useful.

0
 
LVL 9

Accepted Solution

by:
cymbolic earned 200 total points
ID: 1467291
You can use transact SQL and the Create Table syntax in the .execute method of RDO to create a table.  You can also use SQL-DMO by including the SQLOLE object in your project.  It also supports the use of Transact SQL and provides database and table objects and collections, if you're into that metaphor.  A complete SQL-DMO Object model can be downloaded from the MSDN site on the Web.

Here's a copy of an SQL Script that creates a table:

/****** Object:  Table dbo.PchFilLst    Script Date: 7/9/98 3:09:22 PM ******/
if exists (select * from sysobjects where id = object_id('dbo.PchFilLst') and sysstat & 0xf = 3)
      drop table dbo.PchFilLst
GO

/****** Object:  Table dbo.PchFilLst    Script Date: 7/9/98 3:09:22 PM ******/
CREATE TABLE dbo.PchFilLst (
      PchNum char (15) NOT NULL ,
      FilNum int NOT NULL ,
      FilNam char (25) NULL ,
      FilTyp char (1) NULL ,
      BldVer char (15) NULL ,
      LodMsk char (15) NULL ,
      Lap char (1) NULL ,
      UsrAdd char (1) NULL ,
      WrkStn char (1) NULL ,
      Reg char (1) NULL ,
      LapFilLoc char (255) NULL ,
      SrvFilLoc char (255) NULL ,
      CONSTRAINT PK___3__44 PRIMARY KEY  CLUSTERED
      (
            PchNum,
            FilNum
      )
)
GO

The variable number of columns is another problem, but you can solve that yourself by reading the file in VB, and creating your own Insert Into <table> SQL for each row and doing the inserts yourself using the .execute method.
0

Featured Post

SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

Question has a verified solution.

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

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

724 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