Create Table From Text File, Extract Data, Create New Table From Extracted Data....

May 3, 2004

Hello all,

Please help....

I have a text file which needs to be created into a table (let's call it DataFile table). For now I'm just doing the manual DTS to import the txt into SQL server to create the table, which works. But here's my problem....

I need to extract data from DataFile table, here's my query:

select * from dbo.DataFile
where DF_SC_Case_Nbr not like '0000%';

Then I need to create a new table for the extracted data, let's call it ExtractedDataFile. But I don't know how to create a new table and insert the data I selected above into the new one.

Also, can the extraction and the creation of new table be done in just one stored procedure? or is there any other way of doing all this (including the importation of the text file)?

Any help would be highly appreciated.

Thanks in advance.

View 3 Replies


Create CSV File From A Data Table

Mar 6, 2008

 Hi,     I am working on SQL Server 2005 Express and what i want to do is to created a CSV file from a database Table or a View......I search around and find that I Can use BCP for that purpose..Ne other good idea if you people BCP is not working on my PC while i am connected to database server...So plz suggest me the right way to do so...  thanx 

View 5 Replies View Related

How To Create Table On Text File Import?

Sep 27, 2007

Hey guys,
I have a dilemma and hope someone can help.

I don't know of any utilities or commands in SQL that do this but I hope someone does.

What I need to do is something like a bcp import a text file in. I can do that with DTS as well. But what I wanted to do is create a table on the import. So lets say, I am importing a tab-delimited file with column names as the first row that is called ax.txt. On import, it would create the table ax with the column names in the file and then import the data into that table.

I hope I explained it clearly. Please let me know if there is anything I can use to do this without writing lots of code.

I have an idea how to do it the long way but hope there is a utility that already does it.

Thanks in advance.

View 10 Replies View Related

Integration Services :: Create SSIS Package Dynamically For Inserting Data From Flat File To Table?

Sep 30, 2015

I have requirement like  to develop dynamic package for inserting data from flat file to table.

Find below points for more clarification :--

1) if I changed the flat file values and name  in source variable AND  the table name should be also changed based on variable value .

2) it should dynamically mapped with column values with source file as we have to insert data in target table.

See below diagram for more clarification.

View 10 Replies View Related

SSMS Express: Create TABLE && INSERT Data Into Table - Error Msgs 102 && 156

May 18, 2006

Hi all,

I have SQL Server Management Studio Express (SSMS Express) and SQL Server 2005 Express (SS Express) installed in my Windows XP Pro PC that is on Microsoft Windows NT 4 LAN System. My Computer Administrator grants me the Administror Privilege to use my PC. I tried to use SQLQuery.sql (see the code below) to create a table "LabResults" and insert 20 data (values) into the table. I got Error Messages 102 and 156 when I did "Parse" or "Execute". This is my first time to apply the data type 'decimal' and the "VALUES" into the table. I do not know what is wrong with the 'decimal' and how to add the "VALUES": (1) Do I put the precision and scale of the decimal wrong? (2) Do I have to use "GO" after each "VALUES"? Please help and advise.

Thanks in advance,

Scott Chang

USE MyDatabase
CREATE TABLE dbo.LabResults
SampleName varchar(25) NOT NULL,
AnalyteName varchar(25) NOT NULL,
Concentration decimal(6.2) NULL)
--Inserting data into a table
INSERT dbo.LabResults (SampleID, SampleName, AnalyteName, Concentration)
VALUES (1, 'MW2', 'Acetone', 1.00)
VALUES (2, 'MW2', 'Dichloroethene', 1.00)
VALUES (3, 'MW2', 'Trichloroethene', 20.00)
VALUES (4, 'MW2', 'Chloroform', 1.00)
VALUES (5, 'MW2', 'Methylene Chloride', 1.00)
VALUES (6, 'MW6S', 'Acetone', 1.00)
VALUES (7, 'MW6S', 'Dichloroethene', 1.00)
VALUES (8, 'MW6S', 'Trichloroethene', 1.00)
VALUES (9, 'MW6S', 'Chloroform', 1.00)
VALUES (10, 'MW6S', 'Methylene Chloride', 1.00
VALUES (11, 'MW7', 'Acetone', 1.00)
VALUES (12, 'MW7', 'Dichloroethene', 1.00)
VALUES (13, 'MW7', 'Trichloroethene', 1.00)
VALUES (14, 'MW7', 'Chloroform', 1.00)
VALUES (15, 'MW7', 'Methylene Chloride', 1.00
VALUES (16, 'TripBlank', 'Acetone', 1.00)
VALUES (17, 'TripBlank', 'Dichloroethene', 1.00)
VALUES (18, 'TripBlank', 'Trichloroethene', 1.00)
VALUES (19, 'TripBlank', 'Chloroform', 0.76)
VALUES (20, 'TripBlank', 'Methylene Chloride', 0.51)
Msg 102, Level 15, State 1, Line 5
Incorrect syntax near '6.2'.
Msg 156, Level 15, State 1, Line 4
Incorrect syntax near the keyword 'VALUES'.
Msg 102, Level 15, State 1, Line 5
Incorrect syntax near '6.2'.
Msg 156, Level 15, State 1, Line 4
Incorrect syntax near the keyword 'VALUES'.

View 7 Replies View Related

How To Create Table A By Inserting All Data From Table B?

Jan 16, 2005


Anyone can help me?

How to create Table A by inserting all the data from Table B?


View 1 Replies View Related


Feb 20, 2008

select * into dbo.ashutosh from attribute where 1=2


//the logic is to use where clause with 1=2 which will never be true and hence it will not return any row//

View 3 Replies View Related

Create Table From Row Data

Sep 7, 2006

In SQL Server 2000, is it possible to take a table with one field (column), and pivot the table so that the characters in the row data become the field (column) names of another table ( or in a View)? The number of records could vary.

If so, how would I do this?

Sample table;
Create Table dbo.MonthlyData
Categories varchar(30) NOT NULL

Sample data;

Sales Volume 2005-02
TotRefVol 2005-02
Sales Ratio 2005-02
Sales Volume 2005-03
TotRefVol 2005-03
Sales Ratio 2005-03
Sales Volume 2005-04
TotRefVol 2005-04
Sales Ratio 2005-04

View 7 Replies View Related

Create Script Of Table... With Data?

Oct 9, 2007

In SQL Server Management Studio, I can right-click a table and choose:

Script Table as > CREATE To > New Query Editor Window

When I run the script on another database, it creates the table without the data. Is there an option to bring the data (i.e. the contents of the table) along with the table definition?

View 5 Replies View Related

How Can I Create A Cool Data Model Table Map?

Oct 14, 2006

I first got this map from SQL Server Magazine subscription. Now isee it's available to download as a PDF from Microsoft.'ve just installed Visual Studio Team Edition for Database Professionalsand for the next coming weeks i'll get a chance to see what kind of datamodel design capabilities the product offers.My question would be do you know how I can make our databasemodel look cool like this map? Would you know if this is a third partysoftware that does this with nice colors and all?Do you think I can do similar quality data model map using VSTE forDB Pro?Thank you

View 3 Replies View Related

How Can I Create A Clean Copy Of My DB And Keep Lookup Table Data

Nov 27, 2007

I have a database that I have been creating and testing. I have added some junk data and some data into lookup tables. Is there a way to create a clean copy of the db and keep the lookup table data? Also will I be able to create the db under a new name?

View 1 Replies View Related

T-SQL (SS2K8) :: Create Dynamics View Which Contain Data Of All Table

Apr 16, 2014

I have view something like

Create view All_employee
SELECT Emp_Name, Emp_code FROM dbo.Employee
SELECT Emp_Name, Emp_code FROM Emp_201402.Employee

But we have a different "Schema" for same table because we have archive table with same table name but with different schema name. Now we have req to make view which contain data of all table. But I can't seem to figure out how to do it in a view.

SELECT ROW_NUMBER() OVER (ORDER BY SCHEMA_ID), Name FROM sys.schemas where name like '%emloyee%' ORDER BY schema_id ASC

[Code] ....

Don' think that works.

Is this possible with a view or it other way to do it?

View 7 Replies View Related

Create Table: Want A Column With Money Data Type

Dec 14, 2007

Hi all!

I want to create a table. One of the columns should be in the data type MONEY with two digits on the right side of the decimal point.
How is that possible?

Thanks a lot and greetings from vienna


View 2 Replies View Related

How To Create DTS Package For Table Alteration And Movement Of Data

Mar 5, 2008

Peace be on you,

In my organization, we have a database which exceed unto 2 GB. The application on which we are working is developing since the time of asp / cb 6 and in short it is the baby of many developers. It is a kind of ERP which has no documentation.

Problem 1:
Now, to reduce the size of the database we have examined some of the orphan procedures, tables, and columns. Is it possible for me to create a DTS package which create the backup of all the orphan stuff to some other database and delete it from the actual one. Moreover, We still have doubts that some of fields which we think are orphan, might not be. So we need another DTS package which rollback all the changes. (Any Idea for that)

Problem 2:
We want another DTS package which would move the data from one database to another and same rollback DTS for this one. (Any Idea for that)

Problem 3:
How can we use DTS programming to do these tasks ? what benefits do I got from DTS Programming over DTS Wizard.

Any help would be greatly appreciated.

View 4 Replies View Related

DB Design :: Create Table On Given Data Model Diagram

Jul 27, 2015

I never created table on the basis of Data model diagram . I have to create the 3 table on the basis of given Data model diagram. There are 3 tables


I have tried to create 2 table but unable to create 3rd table.

CREATE TABLE [dbo].[md_geographylevel](
[type_key] [int] NOT NULL,
[geog_key] [int] NOT NULL,
[Type_description] [nvarchar](50) NULL,
[Store_flag] [nvarchar](10) NULL,
[Type_short_desciption] [nvarchar](50) NULL,

[Code] ....

I am getting difficulties to create table script for table


How to create the table create script for


View 2 Replies View Related

Create Temp Table To Store Data From Database(mssql)

Jun 26, 2007

I am a starter of and trying to build a web application. Do anyone know how to create a temp table to store data from database? I need to extract data from 3 different tables (Profile,Family,Quali). Therefore, i need to use 3 different queries to extract from the 3 tables and then store it in the temp table. Then, i need to output the data from temp table to the screen. Do anyone can help me?

View 2 Replies View Related

SQL 2012 :: Automatically Create Insert Statements For Table Data

Jun 10, 2014

How to create insert statements of the data from a table for top 'n' rows. I know we can create using generate scripts wizard, but we can't customize the number of rows. In my scenario i got a database with 10 tables where every table got millions of records, but the requirement is to sample out only top 10000 records from each table.

I am planning to generate table CREATE statements from GENERATE Scripts wizard and add this INSERT STATEMENT at the bottom.

EX : INSERT [dbo].[table] ([SERIALID], [BATCHID] VALUES (126751, '9100278GC4PM1', )

View 4 Replies View Related

T-SQL (SS2K8) :: Create Numerous Directories On Server Using Data From Table

Apr 15, 2015

SQL 2008

I have a table that has company id, attachment file name, folderexists columns.

First what I need to do is create a series of folder or directories on a networked server using the company id as the folder name where the folder name does not already exist.

Second I need to move files based on attachment file name and company id to the proper folder.

For those who want to know, this is a remediation project because of a bug in our application.

The application is supposed to created the folder based on company id and then put the attachment in that folder.

View 9 Replies View Related

SQL Server 2012 :: Create Table On Given Data Model Diagram

Jul 27, 2015

I never created table on the basis of Data model diagram . I have to create the 3 table on the basis of given Data model diagram. There are 3 tables


I have tried to create 2 table but unable to create 3rd table. Need to review the script of first 2 table and to create table script for 3rd table.

View 5 Replies View Related

How Can I Create A DTS Package To Update A Table With Data From An Excel Spreadsheet?

Jul 9, 2006

Every month a client sends a spreadsheet with data which we use to update matching rows in a table in the database. I want to automate this using a DTS package but am having quite a bit of trouble accomplishing what I think should be trivial task. I've been attempting to use a Transform Data Task with a modification lookup but I just keep inserting the rows from the source excel spreadsheet in to the existing destination table without ever modifying the existing data.

Any guidance would be greatly appreciated as to a best practice approach.

View 3 Replies View Related

Export Data From Table To Text File

Apr 22, 2002

I need to export data from a table to a text file, where the data in the table is deleted after written to the file. It is simple using DTS, but I want to do the export in "chunks" of data, committing the delete say after every 1000 rows.

My thought was a stored procedure would be easy enough to do this (done these in Oracle many times), but I don't know the quickest way to export a row of data from a stored procedure to a text file. Isn't using a command-line shell too slow? What are my options?

View 1 Replies View Related

Insert Data From A Text File Into The Table

Apr 15, 2006

Hi. my websever mysql manager allows to Insert data from a text file into the table.
currently i have a table with the following fields.

email name country

so i wanto insers data from a text file into this table.
so my question is : how the text file format should be prepared.

i.e. the first record would be > john us

View 2 Replies View Related

Inserting Data From Text File To SQL ME Table

Nov 24, 2006


I have an application taht requires the use of a table. The device that this application works on, has a local memory that does not allow me to insert the 800,000 records that I need. Therefore I have two approaches:

1. To insert less records into my local memory database e.g 40,000 but not row by row, bulk insert is better. How do I do the bulk insert?

2. This is the most prefferable way: To find a way to insert all 800,000 records into a table on the storage card which is 1GB. What do you suggest? Will using threads be helpfull? Any ideas?

I use C# from VS 2005, SQL ME, compact framework 2.0 and windows 4.2.

Thanks in advance,


View 6 Replies View Related

Create Table From Text

Jul 23, 2005

Hi, all. I'm fairly new to SQL, and I have been trying to create a tablefrom a text file. I have been looking at this for days, and can't find theproblem. I get a syntax error " Line 55: Incorrect syntax near'DateUpdated'." Here is the query. Any suggestions would be appreciated,as I am trying to learn and improve.Use ACHgoif exists (select * from dbo.sysobjects where id =object_id(N'[dbo].[ImportFiles]') and OBJECTPROPERTY(id, N'IsProcedure') =1)drop procedure [dbo].[ImportFiles]GOCREATE Procedure ImportFiles@FilePath varchar(1000),@MergeProc varchar(128) = 'MergeData'ASDECLARE @cmd varchar(2000),@Command_String varchar(3000)DECLARE @FileName varchar(1000),@File varchar(1000)CREATE table ##Import (datarow varchar(200))CREATE table #Dir (datarow varchar(200))DROP TABLE ACHParticipantsselect @cmd = 'dir /B' + @FilePathdelete #Dirinsert #Dir exec master..xp_cmdshell @cmddelete #Dir where datarow is null or datarow like '%not found%'while exists (select * from #Dir)BEGINselect @FileName = min(datarow) from #Dirselect @file= @FilePath + @FileNameselect @cmd = 'bulk insert'select @cmd = @cmd + ' ##Import'select @cmd = @cmd + ' from'select @cmd = @cmd + ' @File,'select @cmd = @cmd + ' with (FIELDTERMINATOR='''''select @cmd = @cmd + ',ROWTERMINATOR = '':'')'truncate table ##Import-- import the dataexec (@cmd)-- remove filename just importeddelete #Dir where datarow = @FileNameexec @MergeProcENDdrop table ##Importdrop table #DirGOif exists (select * from dbo.sysobjects where id =object_id(N'[dbo].[MergeData]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)drop procedure [dbo].[MergeData]GOCREATE PROCEDURE MergeDataASCREATE table ACHParticipants(RoutingNum varchar(9),OfficeCode varchar(1),ServicingFRBNum varchar(9),RecordType varchar(1),ChangeDate varchar(8),NewRoutingNum varchar(9),BankName varchar(36),BankAddress varchar(36),City varchar(20),State varchar(2),Zipcode varchar(10),Phone varchar(14),StatusCode varchar(1),DataView varchar(1),Filler varchar(5),DateUpdated datetime)INSERT INTO ACHParticipants(Routing_Number, Office_Code, Servicing_FRB_Number, Record_Type_Code, Change_Date, New_Routing_Number, Customer_Name, Address, City, State_Code, Zipcode, Telephone, Institution_Status_Code, Data_View_Code, Filler, DateUpdated)SELECT Substring(DataRow,1,9) AS RoutingNum,Substring(DataRow,10,1) AS OfficeCode,Substring(DataRow,11,9) AS ServicingFRBNum,Substring(DataRow,20,1) AS RecordType,convert(datetime,Substring(DataRow,21,6)) AS ChangeDate,Substring(DataRow,27,9) AS NewRoutingNum,Substring(DataRow,36,36) AS BankName,Substring(DataRow,72,36) AS BankAddress,Substring(DataRow,108,20) AS City,Substring(DataRow,128,2) AS State,Substring(DataRow,130,5) + '-' + Substring(DataRow,135,4) AS Zipcode,Substring(DataRow,139,3) + '-' + Substring(DataRow,142,3) + '-' +Substring(DataRow,145,4) AS Phone,Substring(DataRow,149,1) AS StatusCode,Substring(DataRow,150,1) AS DataView,Substring(DataRow,151,5) AS FillerDateUpdated datetime AS DateUpdatedFROM ##ImportGOThanks,Karen

View 2 Replies View Related

SSIS 2005: Dynamically Create Data Flow Dest Table If It Does Not Exist?

Sep 20, 2007

Hi all,

I am looking for a way to leave a Data Flow Task destination table name as-is, and have SSIS auto-create the table if it doesn't exist already.

I searched on this in the forums but based on the question it's difficult to kow if it has been answered or not.


I am writing some SSIS packages that need to be executable on another server. Many of the Data Flow Tasks copy data (such as from a Fuzzy Grouping transformation, and lots of other stuff) into a new table. But the other server will not have these tables set up for the first run.

My current solution is to check information_schema.tables and drop IF EXISTS. But, then the Data Flow Task will not work (becase table does not exist). So, I script to new window a create table statement based on the existing table that I use in my dev environment. This is a hack and I want to find a better method.

It is quite possible (although unlikely) that the source columns could be changed in the future, or some query used to pull the data might be modified. If this happens, then I would need to change the CREATE TABLE Execute SQL task. I want my package to accommodate without having to modify it.

When I use the Import/Export Wizard, I can select a table name from the drop down list OR type in a new name. When I type in the new name, it assumes I want to create the table. NOW, is there a way to mimic this in BI Developer Studio? Yep, I saved the Wizard version of the SSIS package and all it does is run a CREATE TABLE statement first.

I am looking for a way to leave a Data Flow Task destination table name as-is, and have SSIS auto-create the table if it doesn't exist already.

Any ideas?

Brian Pulliam

View 12 Replies View Related

Export Data From SQL Database Table To Text File

Jun 22, 2001


I'm trying to export data from one of the table in my SQL 7.0 database into text file. Can someone tell me how can i do this using SQL Query instead of using BCP (command line) ?? Thank you in advance.

View 4 Replies View Related

How Can I Export/import Data On Table To/from Text File

Dec 24, 1998

I needs export data on table to text file so I can process this data
with another database engine ie. Informix.

Can anybody help me to solve this problem ?

View 2 Replies View Related

Read Data From Text File And Insert To Sql Table

Mar 28, 2008

hi my friends
i want read data from text file,and write to my table in sql,
please help me


View 6 Replies View Related

How To Write Selected Table Data To A Text File Daily?

Aug 24, 1999

I want to check a table to see what rows have been updated today, then write to a text file some data from the selected rows; then I want to automate this (DTS package? TSQL stored procedure job?) to run every night at midnight. Is the DTS Wizard the best way, that's what I did, but have not confirmed that it is writing a new text file every day, and does each new version write over the old one?

View 1 Replies View Related

Export Data From Sql Server 2005 Table To Text File

Feb 27, 2008

I want to transfer data from table to a text file.I m trying to use bcp utility and xp_cmdshell.but the export is not successful.
My query is:

EXEC master..xp_cmdshell'bcp "Select * from test..emp" queryout "c:dept.txt" -c -T -x'

and its output is:

Starting copy...
3 rows copied.
Network packet size (bytes): 4096
Clock Time (ms.) Total : 16 Average : (187.50 rows per sec.)

but there is no row copied into c:dept.txt

where is the problem??


View 23 Replies View Related

Import Data From Text File Into A Temp Table In Stored Proc

Oct 1, 2001

can one of you please show me how to import data from a text file into a temp table in a stored proc.

View 1 Replies View Related

SQL Server 2012 :: Loading And Reformatting Text File Data Into Table

May 29, 2015

I am looking for a way to convert the following format into a sql table. The format it is Bib Tex.

Essentially a new row in the table would be for each entry, denoted by an @ logo and each column is denoted by an =, as you can see from the example data no one contains all the possible columns and some fields can be over two lines long.

To load this I was considering loading it into a table as each line being a row. Adding a row number, then a column counting the @ signs in order and essentially grouping each record, then for each group running through and looking for the column keywords 'author' , 'title' etc then splitting the data out into those constituent parts using substring and charindex.

author = "von Hicks, III, Michael",
title = "Design of a Carbon Fiber Composite Grid Structure for the GLAST
Spacecraft Using a Novel Manufacturing Technique",
publisher = "Stanford Press",
year = 2001,

[Code] ....

View 9 Replies View Related

Load Data From Text File Into Some Table Implemented In Stored Procedure.

Nov 8, 2006

Hello, I want to load data from text file to MS SQL DB table.

In MySQL, it is the "LOAD DATA INFILE..." query statement.

What is sutable query if I want to migration from Mysql to MS SQL Server 2005 Express?

View 2 Replies View Related

Copyrights 2005-15, All rights reserved