Showing posts with label created. Show all posts
Showing posts with label created. Show all posts

Thursday, March 22, 2012

Bulk Insert Statement

I am trying to perform bulk insert but it is not working.

I created a table

INSERT INTO [demo].[dbo].[test]

([ID] ,[Plates] ,[Driver])

VALUES

(<ID, int,> ,<Plates, varchar(7),> ,<Driver, varchar(7),>)

I am tryin to insert a file.txt

100, 091-184, DOUG798
101, 406-846, DALL152
102, 384-080, TIZE489
103, 064-460, NAMO927
104, 101-366, CETI001
105, 109-366, JESS111

Any help, please

Juvan

hi Juvan,

the syntax you used is not correct for BULK INSERT statement,
have a look at http://msdn2.microsoft.com/en-us/library/ms188365.aspx for the statement's full synopsis and syntax..

/*

[FILE d:\fmt.txt]

9.0

3

1 SQLCHAR 0 10 "," 1 FirstName "Latin1_General_CI_AS"

2 SQLCHAR 0 10 "," 2 LastName "Latin1_General_CI_AS"

3 SQLCHAR 0 8 "\r\n" 3 BDate "Latin1_General_CI_AS"

[/FILE d:\fmt.txt]

[FILE d:\studs.txt]

Juvan, Bonni, 19701015

Andrea, Montanari, 19651030

[/FILE d:\studs.txt]

*/

SET NOCOUNT ON;

USE tempdb;

GO

CREATE TABLE dbo.Students(

FirstName varchar(10) NOT NULL,

LastName varchar(10) NOT NULL,

BDate datetime NOT NULL

);

GO

BULK INSERT dbo.Students

FROM 'd:\studs.txt'

WITH(FORMATFILE = 'd:\fmt.txt') ;

GO

SELECT * FROM dbo.Students;

GO

DROP TABLE dbo.Students;

--<--

FirstName LastName BDate

- - --

Juvan Bonni 1970-10-15 00:00:00.000

Andrea Montanari 1965-10-30 00:00:00.000

regards

Bulk Insert Question

I have a simple table I have created to do a bulk insert with a SP. Everything works fine but when the sp runs, the first column in the rows are like

"0243567

My bulk insert

BULK INSERT [Mas500_app].[dbo].[Test] FROM 'C:\Documents and Settings\Chris\Desktop\testbulk1.txt' WITH (FIELDTERMINATOR = '"~"', ROWTERMINATOR = '"')

the testbulk.txt file

"0243567"~"08/26/06"

How would I go about in my bulk statement to remove the " from the first column in the row.

ThanksWell there is no such options in bulk statement to remove the " from "0243567

the trailing " is removed becuase you have specified it as the field terminator

however you have two options
1) Change the txt file to remove the " from the first row data
2) issue the follwoing update statement immediately after the bulk insert statement

update [Mas500_app].[dbo].[Test]
set column1 = replace( column1 , " , '' )

HOwever the above replace statement is helpful only if your data in column1 does not contain any " else you will have to go for more elaborate procedures|||I think this might do what you want (it trims the first character off a field value).

UPDATE MyTable
SET MyField = SubString(MyField,2,Len(MyField))

HTH ~Georgesql

Thursday, March 8, 2012

Bulk Insert fails to import data files created on Unix

It seems to me that files created on Unix machines with line terminator \n, or chr(10), cannot be imported using the Bulk Insert statement. Is this a bug, or an oversight by Microsoft? Does this mean that unless one replaces all \n with \r\n, there is no way to use Bulk Insert to import Unix files? This is a very strange behavior by MSSQL. Even lessor programs such as Excel and Word automatically recognize chr(10) as a line termination character. Am I missing something, or is this just the way MSSQL is?

You will need to use a format file, in this you can specify the terminator for the last column in a row.

Have a look in BOL. This page shows an example of a file using /r/n which you can obviously change

ms-help://MS.SQLCC.v9/MS.SQLSVR.v9.en/udb9/html/ecfc546d-f708-45f4-878d-fb71b5fd1a0a.htm

|||

Of if you are using the BULK INSERT TSQL statement look at this page

ms-help://MS.SQLCC.v9/MS.SQLSVR.v9.en/tsqlref9/html/be3984e1-5ab3-4226-a539-a9f58e1e01e2.htm

|||I figured out that the problem has to do with MSSQL's native behavior. It turns out that whenever it sees \n, it automatically converts it to \r\n, without notifiying the user. There are at least three ways to work around this strange behavior: 1) replace every \n in your file with \r\n before using Bulk Insert, 2) build your sql statement dynamically either in a stored procedure or VB.net, i.e., use & chr(10) & ,or + chr(10) +, instead of '\n' as the line terminator in your statement, and 3) load your file into a Datatable via ADO.net, and then insert the entire Datatable into MSSQL.|||

Note sure what figuring out was required, as BOL has an example that just works.

|||

I have never succeeded to convince BULK INSERT to read Unix

files, and I find one of these solutions usually works:

1. See if the process that moved the files from the Unix

machine can correct the line ends (for example, ftp can do

this)

2. Run the Unix utility unix2dos on the files before they

leave the Unix machine, or afterwards, under the Cygwin

Unix shell for Windows. (Or write a tiny command-line

Windows program to do this.)

Steve Kass

Drew University

ktto@.discussions.microsoft.com wrote:

> I figured out that the problem has to do with MSSQL's native behavior.

> It turns out that whenever it sees \n, it automatically converts it to

> \r\n, without notifiying the user. There are at least three ways to work

> around this strange behavior: 1) replace every \n in your file with \r\n

> before using Bulk Insert, 2) build your sql statement dynamically either

> in a stored procedure or VB.net, i.e., use & chr(10) & ,or + chr(10) +,

> instead of '\n' as the line terminator in your statement, and 3) load

> your file into a Datatable via ADO.net, and then insert the entire

> Datatable into MSSQL.

>

Bulk Insert fails to import data files created on Unix

It seems to me that files created on Unix machines with line terminator \n, or chr(10), cannot be imported using the Bulk Insert statement. Is this a bug, or an oversight by Microsoft? Does this mean that unless one replaces all \n with \r\n, there is no way to use Bulk Insert to import Unix files? This is a very strange behavior by MSSQL. Even lessor programs such as Excel and Word automatically recognize chr(10) as a line termination character. Am I missing something, or is this just the way MSSQL is?

You will need to use a format file, in this you can specify the terminator for the last column in a row.

Have a look in BOL. This page shows an example of a file using /r/n which you can obviously change

ms-help://MS.SQLCC.v9/MS.SQLSVR.v9.en/udb9/html/ecfc546d-f708-45f4-878d-fb71b5fd1a0a.htm

|||

Of if you are using the BULK INSERT TSQL statement look at this page

ms-help://MS.SQLCC.v9/MS.SQLSVR.v9.en/tsqlref9/html/be3984e1-5ab3-4226-a539-a9f58e1e01e2.htm

|||I figured out that the problem has to do with MSSQL's native behavior. It turns out that whenever it sees \n, it automatically converts it to \r\n, without notifiying the user. There are at least three ways to work around this strange behavior: 1) replace every \n in your file with \r\n before using Bulk Insert, 2) build your sql statement dynamically either in a stored procedure or VB.net, i.e., use & chr(10) & ,or + chr(10) +, instead of '\n' as the line terminator in your statement, and 3) load your file into a Datatable via ADO.net, and then insert the entire Datatable into MSSQL.|||

Note sure what figuring out was required, as BOL has an example that just works.

|||

I have never succeeded to convince BULK INSERT to read Unix

files, and I find one of these solutions usually works:

1. See if the process that moved the files from the Unix

machine can correct the line ends (for example, ftp can do

this)

2. Run the Unix utility unix2dos on the files before they

leave the Unix machine, or afterwards, under the Cygwin

Unix shell for Windows. (Or write a tiny command-line

Windows program to do this.)

Steve Kass

Drew University

ktto@.discussions.microsoft.com wrote:

> I figured out that the problem has to do with MSSQL's native behavior.

> It turns out that whenever it sees \n, it automatically converts it to

> \r\n, without notifiying the user. There are at least three ways to work

> around this strange behavior: 1) replace every \n in your file with \r\n

> before using Bulk Insert, 2) build your sql statement dynamically either

> in a stored procedure or VB.net, i.e., use & chr(10) & ,or + chr(10) +,

> instead of '\n' as the line terminator in your statement, and 3) load

> your file into a Datatable via ADO.net, and then insert the entire

> Datatable into MSSQL.

>

Bulk Insert Error

Simple test project. Created Flat File connection, database connection (both local), and Bulk Insert Task. When running the package I get the following error:

[Bulk Insert Task] Error: An error occurred with the following error message: "Cannot fetch a row from OLE DB provider "BULK" for linked server "(null)".The OLE DB provider "BULK" for linked server "(null)" reported an error. The provider did not give any information about the error.Bulk load: An unexpected end of file was encountered in the data file.".

I've tried different settings for the Flat File config, and the database connection, but still get the error. Any suggestions would be helpful.

Tks.

Have you looked into the error message? Specifically the part about the task encountering an unexpected end of file?|||Yes. The file seems fine. The Flat File connection tool reads the file fine (i.e. it displays the records appropriately when creating the connection). I can read this file with any number of other tools (e.g. import into Excel).|||

Here's what you can do to narrow down the problem:

1. Use Profiler to capture the bulk insert statement generated by the bulk insert task.

2. Look at the options in the bulk insert statement to make sure they are correct. You may get this error if the options, like row delimiter, are not set correctly. In that case, you can change them in the bulk insert task UI.

You can also run the bulk insert statement outside of SSIS (e.g. Management Studio) to make sure the statement is correct.

Tuesday, February 14, 2012

Building my own Query Designer

I have created a Custom Data Extention to query SharePoint List data directly
from within Reporting Services. I would like to replace the Generic Query
designer with my own code to make selecting columns or adding selection
critera an easier and more friendly process and can see that Microsoft have
built query designers for SAP etc.. so it would appear possible'
I have been unable to find any documentation on developing Query designers
but I am hoping that someone can help me?
Thanks
JasonHello Jason,
You need to create a Visual Studio 2005 Add-on to add your own Query
designer.
There are some sample projects in the Vistual Studio 2005 SDK.
http://www.microsoft.com/downloads/details.aspx?familyid=51a5c65b-c020-4e08-
8ac0-3eb9c06996f4&displaylang=en
And you may refer this web site:
http://msdn2.microsoft.com/en-us/vstudio/aa700819.aspx
Also, this article may be helpful for you to understand the Visual Studio
Add-in
http://www.codeproject.com/csharp/LineCounterAddin.asp
Sincerely,
Wei Lu
Microsoft Online Community Support
==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================This posting is provided "AS IS" with no warranties, and confers no rights.|||Hmmm..I didn't know it was a VS2005 Addin... I've built a few addins for
VS2005 before...I'll take a look.. :)
Thanks!!! :)
"Wei Lu [MSFT]" wrote:
> Hello Jason,
> You need to create a Visual Studio 2005 Add-on to add your own Query
> designer.
> There are some sample projects in the Vistual Studio 2005 SDK.
> http://www.microsoft.com/downloads/details.aspx?familyid=51a5c65b-c020-4e08-
> 8ac0-3eb9c06996f4&displaylang=en
> And you may refer this web site:
> http://msdn2.microsoft.com/en-us/vstudio/aa700819.aspx
> Also, this article may be helpful for you to understand the Visual Studio
> Add-in
> http://www.codeproject.com/csharp/LineCounterAddin.asp
> Sincerely,
> Wei Lu
> Microsoft Online Community Support
> ==================================================> When responding to posts, please "Reply to Group" via your newsreader so
> that others may learn and benefit from your issue.
> ==================================================> This posting is provided "AS IS" with no warranties, and confers no rights.
>|||Hi ,
How is everything going? Please feel free to let me know if you need any
assistance.
Sincerely,
Wei Lu
Microsoft Online Community Support
==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================This posting is provided "AS IS" with no warranties, and confers no rights.|||Wei Lu,
I'm actually at the .Net Roadshow in Boston this week so I have not had a
chance to get into the code.
While I know how to build VS2005 addins, is there a defined interface for
building Query designers? I se how to launch the designer in the
RSReportDesigner.config but I'm wondering if there is any documentation on
the interface I would need to implement just like I had to when building the
Sharepoint Data Extension.
I can see designers like:
Microsoft.ReportingServices.QueryDesigners
Microsoft.ReportingServices.QueryDesigners.Essbase
Microsoft.ReportingServices.QueryDesigners.SapBw
Now I'd like to "implement" my own...Any help on the interface I need to
build to make it work would be gratefully appreciated..
Thanks
Jason
"Wei Lu [MSFT]" wrote:
> Hi ,
> How is everything going? Please feel free to let me know if you need any
> assistance.
> Sincerely,
> Wei Lu
> Microsoft Online Community Support
> ==================================================> When responding to posts, please "Reply to Group" via your newsreader so
> that others may learn and benefit from your issue.
> ==================================================> This posting is provided "AS IS" with no warranties, and confers no rights.
>|||Hello Jason,
Well, that will be some difficult if you want the Visual Studio load your
custom designer and embedded it into the project.
My suggestion is that you only use the addin to make you could generate the
query to query the datasource and add it to the querytext in the xml.
Sincerely,
Wei Lu
Microsoft Online Community Support
==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================This posting is provided "AS IS" with no warranties, and confers no rights.|||Hi ,
How is everything going? Please feel free to let me know if you need any
assistance.
Sincerely,
Wei Lu
Microsoft Online Community Support
==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================This posting is provided "AS IS" with no warranties, and confers no rights.|||If you got this working I would like to test it for you...
"Jason" wrote:
> Wei Lu,
> I'm actually at the .Net Roadshow in Boston this week so I have not had a
> chance to get into the code.
> While I know how to build VS2005 addins, is there a defined interface for
> building Query designers? I se how to launch the designer in the
> RSReportDesigner.config but I'm wondering if there is any documentation on
> the interface I would need to implement just like I had to when building the
> Sharepoint Data Extension.
> I can see designers like:
> Microsoft.ReportingServices.QueryDesigners
> Microsoft.ReportingServices.QueryDesigners.Essbase
> Microsoft.ReportingServices.QueryDesigners.SapBw
> Now I'd like to "implement" my own...Any help on the interface I need to
> build to make it work would be gratefully appreciated..
> Thanks
> Jason
>
> "Wei Lu [MSFT]" wrote:
> > Hi ,
> >
> > How is everything going? Please feel free to let me know if you need any
> > assistance.
> >
> > Sincerely,
> >
> > Wei Lu
> > Microsoft Online Community Support
> >
> > ==================================================> >
> > When responding to posts, please "Reply to Group" via your newsreader so
> > that others may learn and benefit from your issue.
> >
> > ==================================================> > This posting is provided "AS IS" with no warranties, and confers no rights.
> >
> >

Monday, February 13, 2012

building models with views

Using data in SS2000 and RS2005. I tried to build a model from a view that I
created. I got the "tables does not have a primary key" error. Do I have to
use indexed views in the model?
--
Dan D.Dan,
You will need to specify a 'logical' primary key in your DSV (Data Source
View)
Bret
"Dan D." wrote:
> Using data in SS2000 and RS2005. I tried to build a model from a view that I
> created. I got the "tables does not have a primary key" error. Do I have to
> use indexed views in the model?
> --
> Dan D.

Friday, February 10, 2012

Build reports using Report Designer using Models

Once a Model is created, is ther query builder the only tool that can be used
to create a report from the Model or can we use Report Designer to build
reports off a Model?
Thanks in advance!I guess I should have clarified I am work with the 2005 Beta version of
Reporting Services. If anyone has any idea, please let me know.
Thanks!
"clutch" wrote:
> Once a Model is created, is ther query builder the only tool that can be used
> to create a report from the Model or can we use Report Designer to build
> reports off a Model?
> Thanks in advance!