Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.4k views
in Technique[技术] by (71.8m points)

sql server - How to open a rpt file as a SQL Table?

I have a rpt dump that one of my colleagues gave. I need to open this file as a SQL Table (I presume that this is possible since he generated the rpt dump from the SQL Table).

How do I do that. I am using SQL Server Management Studio. I can also open the rpt file as a separate file in SSMS.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Though this answer is late, I didn't see a canonical answer to the problem of opening the .rpt file format and writing it to a SQL table.

  1. In SQL Server Management Studio in Object Explorer, right click on the database you want to load the file into and choose Tasks... Import Data.

  2. Choose Flat File Source, select your file, then ensure the screen is setup to match the following screenshot (Code page=65001 UTF-8, Format=Ragged right, Column names in the first data row). Then click Next.

set Flat File Source and Ragged right

  1. Click on the first character of each column (see the yellow highlights in the screenshot below for where to click) to insert columns at the appropriate spots:

define fixed width columns

  1. Click the Advanced tab on the left. Go through each column name and remove the spaces from the end of the column name. Fix the data types as you see fit. Warning the first few columns may need to be strings because of the "(NNN affected rows)" file footer.

Fix column name trailing spaces and data types

  1. Go to the Preview tab on the left, change the "Data rows to skip" to 1 and click Refresh:

Data rows to skip

  1. Click the Next button and setup your connection to your SQL database:

Destination DB connection info

  1. Click next and type in the name of your table in the format [dbo].[MyTable] then click Edit Mappings and confirm the column data types match. String (DT_STR) columns should be varchar columns here. Unicode string (DT_WSTR) should be nvarchar columns here.

  2. Click Next and Finish to run immediately. You should see success messages not errors hopefully:

Success

  1. There is a footer which says "(NNN rows affected)" (where NNN is the row count of your file). Query the destination SQL table to find that row and delete it. select * from MyTable where MyColumn1 like '%(%' may help you find that row. Please confirm that query returns only one row before you delete it.

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...