Showing posts with label values. Show all posts
Showing posts with label values. Show all posts

Friday, March 23, 2012

Importing NULL into table SQL Server 2005

I've tried to import a text file into a table using the Import/export wizard.

My problem starts with some columns that should have NULL values (i.e. zero-length string) but the wizard doesn't recognize that it's NULL.

How do I solve the problem?

Thanks,

Mich

First, a zero-length is not NULL. NULL is a special character.

If you want NULLs to be inserted, open up the package and edit it (that the import/export wizard created for you) and add a derived column transformation before going to the destination.

Use an expression similar to this for each of your columns:

[myColumn] == "" ? NULL(DT_WSTR,20) : [myColumn]

I'm going by memory, but I believe that would work. The above assumes myColumn has a length of 20 bytes.

|||

Thank you for your answer.

My knowledge of the import/export wizard is limited.

I would like to know whether the expression should be added in the "Suggest Types" button or elsewhere.

Is the expression related to the destination column names or the columns the Wizard created?

I'd appreciate it if you could give me a step-by-step guide on how to do it, since I found the sql help file very unhelpful.

Thank you again.

Importing Multiple XML Field values

Hi,
Does anyone know how to make SQLXMLBulkLoad accept a SQL file if it has a
field repeated with more than 1 value. For example
<ROOT>
<Cust>
<details>
<Val1>23</Val1>
<Val2>44</Val2>
<Val3>16</Val3>
<Val3>77</Val3>
<Val4>47</Val4>
</details>
</Cust>
</ROOT>
As Val3 appears twice in the file, SQLXMLBulkLoad fails because it already
has a mapping for this field. Is there a way to modify the schema definition
to allow for this?
I don't actually care which of the values for Val3 the import process saves,
although I would like one or the other.
The schema currently looks something like:
<schema xmlns="http://www.w3.org/2001/XMLSchema"
xmlns:sql="urn:schemas-microsoft-com:mapping-schema">
<element name="Cust" sql:relation="CustTable" >
<complexType>
<sequence>
<element name="Val1" sql:field="CusVal1" type="integer" />
<element name="Val2" sql:field="CusVal2" type="integer" />
<element name="Val3" sql:field="CusVal3" type="integer" />
<element name="Val4" sql:field="CusVal4" type="integer" />
<sequence>
<complexType>
<element>
<schema>
Thanks
Bod
There is no way to get bulkload to work this way.
Your options would be to:
1. clean the data ahead of time using XSLT, or
2. do the inserts using the Server's nodes() method
This article has examples of using nodes()
http://msdn.microsoft.com/library/de.../forxml2k5.asp
|||Thanks Todd. Not my favourite answer but your confirmation that I can't do
it saves me wasting hours of trying...
Bod
"Todd Pfleiger [MSFT]" wrote:

> There is no way to get bulkload to work this way.
> Your options would be to:
> 1. clean the data ahead of time using XSLT, or
> 2. do the inserts using the Server's nodes() method
> This article has examples of using nodes()
> http://msdn.microsoft.com/library/de.../forxml2k5.asp
>
sql

Importing Multiple XML Field values

Hi,
Does anyone know how to make SQLXMLBulkLoad accept a SQL file if it has a
field repeated with more than 1 value. For example
<ROOT>
<Cust>
<details>
<Val1>23</Val1>
<Val2>44</Val2>
<Val3>16</Val3>
<Val3>77</Val3>
<Val4>47</Val4>
</details>
</Cust>
</ROOT>
As Val3 appears twice in the file, SQLXMLBulkLoad fails because it already
has a mapping for this field. Is there a way to modify the schema definitio
n
to allow for this?
I don't actually care which of the values for Val3 the import process saves,
although I would like one or the other.
The schema currently looks something like:
<schema xmlns="http://www.w3.org/2001/XMLSchema"
xmlns:sql="urn:schemas-microsoft-com:mapping-schema">
<element name="Cust" sql:relation="CustTable" >
<complexType>
<sequence>
<element name="Val1" sql:field="CusVal1" type="integer" />
<element name="Val2" sql:field="CusVal2" type="integer" />
<element name="Val3" sql:field="CusVal3" type="integer" />
<element name="Val4" sql:field="CusVal4" type="integer" />
<sequence>
<complexType>
<element>
<schema>
Thanks
BodThere is no way to get bulkload to work this way.
Your options would be to:
1. clean the data ahead of time using XSLT, or
2. do the inserts using the Server's nodes() method
This article has examples of using nodes()
http://msdn.microsoft.com/library/d...r />
ml2k5.asp|||Thanks Todd. Not my favourite answer but your confirmation that I can't do
it saves me wasting hours of trying...
Bod
"Todd Pfleiger [MSFT]" wrote:

> There is no way to get bulkload to work this way.
> Your options would be to:
> 1. clean the data ahead of time using XSLT, or
> 2. do the inserts using the Server's nodes() method
> This article has examples of using nodes()
> http://msdn.microsoft.com/library/d.../>
rxml2k5.asp
>|||Bod-
Can you post your final schema file that you are using for this bulk
load?
Thanks
Brian
briankudera
---
Posted via http://www.mcse.ms
---
View this thread: http://www.mcse.ms/message2239821.html

Importing MSAccess data into SQL Tables

I am attempting to import data from an MS Access 2000 table into a SQL
Server 2000 table, but NULL values in the Access table are causing the DTS
import to fail.
I thought that if I defined a column in SQL as 'NOT NULL', but assigned a
default value of '', then it would allow an import containing a NULL, which
it would convert to a ''. But I guess I was wrong? Is there is a way to
import MSAccess data containing nulls into a SQL table where the nulls would
be automatically be converted to ''?
Thanks!
Mark
Here is the definition for the SQL table:
CREATE TABLE [dbo].[creditcard] (
[CARD_NAME] [nchar] (30) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL ,
[CARD_ABB] [nchar] (20) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL ,
[ACTIVE] [nchar] (1) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL
) ON [PRIMARY]
GO
ALTER TABLE [dbo].[creditcard] ADD
CONSTRAINT [DF_creditcard_CARD_NAME] DEFAULT ('') FOR [CARD_NAME],
CONSTRAINT [DF_creditcard_CARD_ABB] DEFAULT ('') FOR [CARD_ABB],
CONSTRAINT [DF_creditcard_ACTIVE] DEFAULT ('') FOR [ACTIVE]
GO
Mark,
make sure that on the options tab of the transform data task, 'check
constraints' is enabled.
HTH,
Paul Ibison
|||I'm sorry but I don't see the option 'check constraints'. I am running the
'Data Transformation Services Import/Export wizard'.
Here are the screens I see:
1) Choose a data source: I choose the access database
2) Choose a destination: I choose the target database
3) Specify Table Copy or Query: I choose 'Copy table(s) and view(s) from the
source database
4) Select Source Tables and Views: I select my source table and target table
here
5) Save, schedule and replicate package: I choose 'Run Immediately'
6) Completing the DTS Import/Export Wizard: I choose 'Finish' to run the
import.
At this point it appears to import a number of records and then I get the
popup indicating that it can not import the record with the NULL value in
the column.
In all of that I'm afraid I could not see a transform data task. I hate to
be dense, but could you elaborate on where I should look for that?
Many thanks!
Mark
"Paul Ibison" <Paul.Ibison@.Pygmalion.Com> wrote in message
news:eNw%23ZyPQEHA.3708@.TK2MSFTNGP10.phx.gbl...
> Mark,
> make sure that on the options tab of the transform data task, 'check
> constraints' is enabled.
> HTH,
> Paul Ibison
>
|||DTS can only carry over constraint if you go between SQL Servers. I think that Access comes with some upsizing
wizard, you might want to check in an Access groups.
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
"Mark Findlay" <mfindlay@.speakeasy.org> wrote in message news:%238kPFkQQEHA.2876@.TK2MSFTNGP09.phx.gbl...
> I'm sorry but I don't see the option 'check constraints'. I am running the
> 'Data Transformation Services Import/Export wizard'.
> Here are the screens I see:
> 1) Choose a data source: I choose the access database
> 2) Choose a destination: I choose the target database
> 3) Specify Table Copy or Query: I choose 'Copy table(s) and view(s) from the
> source database
> 4) Select Source Tables and Views: I select my source table and target table
> here
> 5) Save, schedule and replicate package: I choose 'Run Immediately'
> 6) Completing the DTS Import/Export Wizard: I choose 'Finish' to run the
> import.
> At this point it appears to import a number of records and then I get the
> popup indicating that it can not import the record with the NULL value in
> the column.
> In all of that I'm afraid I could not see a transform data task. I hate to
> be dense, but could you elaborate on where I should look for that?
> Many thanks!
> Mark
> "Paul Ibison" <Paul.Ibison@.Pygmalion.Com> wrote in message
> news:eNw%23ZyPQEHA.3708@.TK2MSFTNGP10.phx.gbl...
>
|||Mark,
the package uses a data transform task in the background which has loads of
properties that are not exposed in the wizard, so the best thing to do is to
save the package without running it. After that, open it and double-click
the data transform task. On the final tab, you'll see the option I'm talking
about. The check constraints option should initiate the default's use.
HTH,
Paul Ibison

Wednesday, March 21, 2012

Importing from Excel

I am having a problem with DTS importing NULL values from an Excel spreadsheet when there are numbers and text in the same column. Other than that, the import works fine. I am using VBScript in an ASP web page to create and execute a DTS package to import an Excel file.

I have read Allan Mitchell's article about using IMEX=1 (http://www.sqldts.com/default.aspx?254). I added IMEX=1 and modified the registry setting, but when I do that NO data at all is imported.

Any ideas? My code is very long, so I'll only post it if you'd really like to see it.

Much thanks in advance!

BillI would export the excel file into a delimited file - the ms driver for excel causes too many headaches. Also, did you modify the TypeGuessRows setting in your registry ?|||Originally posted by rnealejr
I would export the excel file into a delimited file - the ms driver for excel causes too many headaches. Also, did you modify the TypeGuessRows setting in your registry ?

I did modify the TypeGuessRows setting to 0. Is there a way to programmatically export the Excel file to a CSV file?

Thanks,

Bill|||It has been a while since I used the TypeGuessRows - but I believe setting it to 0 will not work - you have to explicitly supply a value (something big enough to sample your data).

Programmatically - Do you mean from within sql server or any executable ?|||Originally posted by rnealejr
It has been a while since I used the TypeGuessRows - but I believe setting it to 0 will not work - you have to explicitly supply a value (something big enough to sample your data).

Programmatically - Do you mean from within sql server or any executable ?

I read somewhere to set it to 0 and use IMEX=1. I just tried setting it to 16 and 8, but neither of those worked either.

Actually, when I said programatically I meant VBScript, but I guess that's for the VBScript forum!

Thanks,

Bill|||You can create an excel object - open the workbook - use the saveas method for the workbook.|||Originally posted by rnealejr
You can create an excel object - open the workbook - use the saveas method for the workbook.

Where can I find information on using the excel object's saveas function? I'm sure there are a number of options, and I'd like to take a look at them.

Thanks!

Bill|||Here is the snapshot from the help (Also, look for a vbaxl9.chm file on your computer):

Saves changes to the sheet (Syntax 1) or workbook (Syntax 2) in a different file.

Syntax 1

expression.SaveAs(Filename, FileFormat, Password, WriteResPassword, ReadOnlyRecommended, CreateBackup, AddToMru, TextCodePage, TextVisualLayout)

Syntax 2

expression.SaveAs(Filename, FileFormat, Password, WriteResPassword, ReadOnlyRecommended, CreateBackup, AccessMode, ConflictResolution, AddToMru, TextCodePage, TextVisualLayout)

expression Required. An expression that returns a Chart or Worksheet object (Syntax 1) or a Workbook object (Syntax 2).

Filename Optional Variant. A string that indicates the name of the file to be saved. You can include a full path; if you dont, Microsoft Excel saves the file in the current folder.

FileFormat Optional Variant. The file format to use when you save the file. For a list of valid choices, see the FileFormat property. For an existing file, the default format is the last file format specified; for a new file, the default is the format of the version of Excel being used.

Password Optional Variant. A case-sensitive string (no more than 15 characters) that indicates the protection password to be given to the file.

WriteResPassword Optional Variant. A string that indicates the write-reservation password for this file. If a file is saved with the password and the password isnt supplied when the file is opened, the file is opened as read-only.

ReadOnlyRecommended Optional Variant. True to display a message when the file is opened, recommending that the file be opened as read-only.

CreateBackup Optional Variant. True to create a backup file.

AccessMode Optional Variant. The workbook access mode. Can be one of the following XlSaveAsAccessMode constants: xlShared (shared list), xlExclusive (exclusive mode), or xlNoChange (dont change the access mode). If this argument is omitted, the access mode isnt changed. This argument is ignored if you save a shared list without changing the file name. To change the access mode, use the ExclusiveAccess method.

ConflictResolution Optional Variant. Specifies the way change conflicts are resolved if the workbook is a shared list. Can be one of the following XlSaveConflictResolution constants: xlUserResolution (display the conflict-resolution dialog box), xlLocalSessionChanges (automatically accept the local users changes), or xlOtherSessionChanges (accept other changes instead of the local users changes). If this argument is omitted, the conflict-resolution dialog box is displayed.

AddToMru Optional Variant. True to add this workbook to the list of recently used files. The default value is False.

TextCodePage Optional Variant. Not used in U.S. English Microsoft Excel.

TextVisualLayout Optional Variant. Not used in U.S. English Microsoft Excel.

The following are the available file formats:

xlAddIn
xlCSV

xlCSVMac

xlCSVMSDOS

xlCSVWindows

xlCurrentPlatformText

xlDBF2

xlDBF3

xlDBF4

xlDIF

xlExcel2

xlExcel2FarEast

xlExcel3

xlExcel4

xlExcel4Workbook

xlExcel5

xlExcel7

xlExcel9795

xlHTML

xlIntlAddIn

xlIntlMacro
xlSYLK
xlTemplate

xlTextMac

xlTextMSDOS

xlTextPrinter

xlTextWindows

xlUnicodeText

xlWJ2WD1

xlWK1

xlWK1ALL

xlWK1FMT

xlWK3

xlWK4

xlWK3FM3

xlWKS

xlWorkbookNormal

xlWorks2FarEast

xlWQ1

xlWJ3

xlWJ3FJ3|||Awesome, thanks!

So if I do this:

<code>
set xlApp = CreateObject("excel.application")
xlApp.Workbooks.Open <filename>
xlApp.ActiveWorkbook.SaveAs <newFileName>, xlCSVWindows
xlApp.ActiveWorkbook.Close
xlApp.Quit
Set xlApp = Nothing
</code>

It would save it as a CSV file?

Thanks!

Bill|||Yes, that looks good. Let me know if there are any problems.|||Originally posted by rnealejr
Yes, that looks good. Let me know if there are any problems.

Thanks, I'm going to try to give it a test today!|||Originally posted by rnealejr
Yes, that looks good. Let me know if there are any problems.

Okay, I tried that code and I'm getting the following error message:

Microsoft Excel error '800a03ec'
SaveAs method of Workbook class failed

Any ideas?

Thanks!

Bill|||Originally posted by rnealejr
Yes, that looks good. Let me know if there are any problems.

Okay, I may have found the issue, but I'm not sure. I saved the current workbook file format value to a variable and printed it to the screen. The value was -4143. Is the fileformat value supposed to be a number or the values from the help file (i.e., xlCSV)?

Thanks for all your help!

Bill|||I do not have to vb at the moment to confirm but the xlCSV value should be and the xlWindowsCSV is 23.|||Also, sorry for the delay - your post got buried.|||Originally posted by rnealejr
I do not have to vb at the moment to confirm but the xlCSV value should be and the xlWindowsCSV is 23. \

No problem on the delay, I really appreciate the help - is there a list of these values anywhere? I've been looking, but I must not be using the right terminology.

Thanks!

Bill|||This link might be helpful:

link (http://techsupt.windowware.com/TS/T000001033005F9.html)

Monday, March 19, 2012

importing excel column with multiple values separated by '/'

I would like to import two columns from an excel file into a sql server
table as an area code - time zone look up.
The area code column sometimes has multiple area codes in the area code
cell. eg. 207/208/209.
What is a good way to import those two columns so that 3 table rows are
created for each of those Excel rows that contain these multiple values
separated by the '/' character?
Thank you,
GregOn Wed, 1 Mar 2006 07:32:52 -0800, hazz wrote:

>I would like to import two columns from an excel file into a sql server
>table as an area code - time zone look up.
>The area code column sometimes has multiple area codes in the area code
>cell. eg. 207/208/209.
>What is a good way to import those two columns so that 3 table rows are
>created for each of those Excel rows that contain these multiple values
>separated by the '/' character?
Hi Greg,
Some useful techniques are disccussed at
http://www.sommarskog.se/arrays-in-sql.html
Hugo Kornelis, SQL Server MVP|||Thank you Hugo, I'll take a look !
"Hugo Kornelis" <hugo@.perFact.REMOVETHIS.info.INVALID> wrote in message
news:spdc0210aq8daomldhm1lmbpviqf7hp4gi@.
4ax.com...
> On Wed, 1 Mar 2006 07:32:52 -0800, hazz wrote:
>
> Hi Greg,
> Some useful techniques are disccussed at
> http://www.sommarskog.se/arrays-in-sql.html
> --
> Hugo Kornelis, SQL Server MVP

Monday, March 12, 2012

Importing Date Values from a flat file into the database

Hi

I am trying to to import a flat file into a table in my database, i get all the values right except for the date, it keeps on inserting NULL values into the date fields.

The date format in the flat file is '20070708' etc.

Does anyone know what i can do to fix this?

I've tried to change the datatype values that it imports, but it still ignores it and inserts NULL values

Any help will be greatly appreciated

Kind Regards

Carel Greaves

Search this forum for "YYYYMMDD" and you'll find your answer along with examples.

Basically, you need to substring the date field into the various date parts and then assemble a date in the format of perhaps mm/dd/yyyy before converting into a datetime field.|||

Thanks