Solved

How to create a SQL Server Table using CSV text file

Posted on 1998-07-30
3
133 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
  • 2
3 Comments
 
LVL 9

Expert Comment

by:cymbolic
Comment Utility
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
Comment Utility
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
Comment Utility
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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

728 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now