Showing posts with label text. Show all posts
Showing posts with label text. Show all posts

Saturday, February 25, 2012

Data Values Validation

Hello all...I am trying to validate that the new work date that is being imported from the text file does not exist in the table. So in other words I do not want duplicate data. This is what I haveSqlDataReader dr =newSqlDataReader(); SqlParameter sp =newSqlParameter("@.WorkDate", Data.SqlDbType.datetime, 8, Data.ParameterDirection.Input); if (dr.HasRows) sp ="@.WorkDate"; else *How does that look? Am I in the ball part…

Try using a stored procedure but instead of

INSERT INTO tablename (WorkDate) VALUES (@.WorkDate)

have

IF NOT EXISTS(SELECT * FROM tablename WHERE WorkDate =@.WorkDate)
INSERT INTO tablename (WorkDate) VALUES (@.WorkDate)

That way you can call the stored procedure passing in the WorkDate value, but a record will only be inserted if the value does not already exist.

|||

Thanks TAT for your help... question, what if a record in there with the same date how would I let the user know?

|||

To let the user know, you need an additional parameter so your stored procedure would look like this

SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author: <Author,,Name>
-- Create date: <Create Date,,>
-- Description: Add record if not already on file
-- =============================================
CREATE PROCEDURE dbo.usp_TableNameAdd
@.WorkDate DateTime,
@.Exists BIT OUTPUT
AS
SET NOCOUNT ON;
SET @.Exists = 0
IF NOT EXISTS(SELECT * FROM tablename WHERE WorkDate = @.WorkDate)
INSERT INTO tablename (WorkDate) VALUES (@.WorkDate)
ELSE
SET @.Exists = 1
GO

|||

Another way could be to raise user friendly error message from within your SP. Read BOL for RAISERROR.

|||

I have a few more questions. When calling the sp I am getting an error message also in the SP the staring lines

SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

are not working for me, is there something I am not seeing.

namespace WindowsApplication2
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void button1_Click(object sender, EventArgs e)
{
//Pull from Text File in from Network Drive
string Source = @."\.\J-1119.txt";
string Date = "";
string O1 = "";
string A1;
string P1;
string R1;
string LineIn;
StreamReader InFile = new StreamReader(Source);

***TRYING TO CALL MY SP****
SqlCommand SC = new SqlCommand("SP_PromoNoDups", sConnect);

SC.Parameters.Add(new SqlParameter("@.WorkDate", WorkDate));
// SqlCommand SC = new SqlCommand("Select * from [tblname]", sConnect);
SC.CommandType = CommandType.StoredProcedure;

LineIn = InFile.ReadLine();
// pos is the location of the cursor
int pos = LineIn.IndexOf("WORK DATE:");
if (pos > 0)
{
Date = LineIn.Substring(pos + 10, 10).Trim();
}
while (LineIn != null)
{
if (LineIn.IndexOf("O1:") == 2)
{
if (LineIn.Length > 10)
{
O1 = LineIn.Substring(10).Trim();
}
else
{
O1 = "";
}
LineIn = InFile.ReadLine();
LineIn = InFile.ReadLine();
while (LineIn != null && LineIn.Trim() != "")
{
P1 = LineIn.Substring(2, 5).Trim();
A1 = LineIn.Substring(19, 20).Trim();
R1 = LineIn.Substring(41, 6).Trim();
string Adjustment = LineIn.Substring(57).Trim(); LineIn = InFile.ReadLine();
if (LineIn.IndexOf("mane") >= 0)
{
break;
} SC.CommandType = LineOut;(Erroring out here)
SC.ExecuteReader();
// if page header - look for next O1
}
LineIn = InFile.ReadLine();
LineIn = InFile.ReadLine();
}
InFile.Close();
}
}
}
}

Friday, February 24, 2012

Data Types list

Hi all,

Im trying to find a list of the different datatypes used when importing a text file,

Such as float [DT_R4], Currency [DT_CY], four-byte signed integer [DT_14] etc etc

I would like to use the list to accurately match up datatypes on paper before I build a package so I can also double check them with friends to see if they are the right one's to use

So I just wondering if anyone knew a place where they were stored Ive gone through the BOL but to no avail.

Small problem really but it would be very handy for me.

Thanks

I wrote out the list this morning, if anyone else ever needs

Boolean [DT_BOOL]
byte stream [DB_BYTES]
currency [DT_CY]
database date [DT_DBDATE]
database time [DT_DBTIME]
database timestamp [DT_DBTIMESTAMP]
date [DT_DATE]
decimal [DT_DECIMAL]
double-precision float [DT_R8]
eight-byte signed integer [DT_18]
eight-byte unsigned integer [DT_U18]
file timestamp [DT_FILETIME]
float [DT_R4]
four-byte signed integer [DT_I4]
four-byte unsigned integer [DT_UI4]
image [DT_IMAGE]
single-byte signed integer [DT_I1]
single-byte unsigned integer [DT_UI1]
string [DT_STR]
text stream [DT_TEXT]
two-byte signed integer [DT_I2]
two-byte unsigned integer [DT_UI2]
Unicode string [DT_WSTR]
unicode text string [DT_NTEXT]
unique identifier [DT_GUID]

GL all

Data types

Hi everyone,
Which is better to use for datatypes nvarchar or varchar?
In access it is a text datatype. For instance i use in access an column with
datatype text, length 100. When upsizing sql server convert this into
nvarchar(100).
Should i leave it this way or is it better to change it to a suitable
datatype.nvarchar uses twice the storage space but allows for storage of more
characters / symbols to support various languages.
If your access db is in a non enlgish language, it's likely best for you to
use nvarchar.
Regards,
Greg Linwood
SQL Server MVP
"Ezekiël" <ezekiel@.lycos.nl> wrote in message
news:eUnabfTyDHA.1996@.TK2MSFTNGP12.phx.gbl...
> Hi everyone,
> Which is better to use for datatypes nvarchar or varchar?
> In access it is a text datatype. For instance i use in access an column
with
> datatype text, length 100. When upsizing sql server convert this into
> nvarchar(100).
> Should i leave it this way or is it better to change it to a suitable
> datatype.
>|||nvarchar can handle unicode characters
varchar cannot
if you need to deal with these characters for example
french and spanish have accent marks and these are fairly
common within people names and place names, then you need
nvarchar. The downside is that it is twice as large (in
storage terms) as varchar because each character required
two bytes, varchar characters require 1 byte.
regards & Merry Christmas,
Mark Baekdal
www.dbghost.com
>--Original Message--
>Hi everyone,
>Which is better to use for datatypes nvarchar or varchar?
>In access it is a text datatype. For instance i use in
access an column with
>datatype text, length 100. When upsizing sql server
convert this into
>nvarchar(100).
>Should i leave it this way or is it better to change it
to a suitable
>datatype.
>
>.
>|||Hi Mark,
Thx for the explaination. Does the performance sql server decreases if
diskspace is not a problem or does sql not work that way?
"mark baekdal" <anonymous@.discussions.microsoft.com> wrote in message
news:07da01c3c941$52d93650$a301280a@.phx.gbl...
> nvarchar can handle unicode characters
> varchar cannot
> if you need to deal with these characters for example
> french and spanish have accent marks and these are fairly
> common within people names and place names, then you need
> nvarchar. The downside is that it is twice as large (in
> storage terms) as varchar because each character required
> two bytes, varchar characters require 1 byte.
> regards & Merry Christmas,
> Mark Baekdal
> www.dbghost.com
> >--Original Message--
> >Hi everyone,
> >
> >Which is better to use for datatypes nvarchar or varchar?
> >In access it is a text datatype. For instance i use in
> access an column with
> >datatype text, length 100. When upsizing sql server
> convert this into
> >nvarchar(100).
> >
> >Should i leave it this way or is it better to change it
> to a suitable
> >datatype.
> >
> >
> >.
> >|||Performance will decrease... The reason is that rows may be twice as long,
therefore half as many rows will fit on a page... This means,
1. Twice as much IO is required to get the same number of rows
2. The rows take up twice as much space in memory, which means OTHER data
gets bumped out of memory, which means OTHER folks have to do more IO as
well..
Use Nvarchar IF you need to store information in ANY language, But if you
only need to store data in latin based languages,,, varchar would be better.
--
Wayne Snyder, MCDBA, SQL Server MVP
Computer Education Services Corporation (CESC), Charlotte, NC
www.computeredservices.com
(Please respond only to the newsgroups.)
I support the Professional Association of SQL Server (PASS) and it's
community of SQL Server professionals.
www.sqlpass.org
"Ezekiël" <ezekiel@.lycos.nl> wrote in message
news:eUnabfTyDHA.1996@.TK2MSFTNGP12.phx.gbl...
> Hi everyone,
> Which is better to use for datatypes nvarchar or varchar?
> In access it is a text datatype. For instance i use in access an column
with
> datatype text, length 100. When upsizing sql server convert this into
> nvarchar(100).
> Should i leave it this way or is it better to change it to a suitable
> datatype.
>|||Usually you will have a slight decrease in performance
using nvarchar although this should be neglible.
regards,
Mark Baekdal
www.dbghost.com
>--Original Message--
>Hi Mark,
>Thx for the explaination. Does the performance sql
server decreases if
>diskspace is not a problem or does sql not work that way?
>"mark baekdal" <anonymous@.discussions.microsoft.com>
wrote in message
>news:07da01c3c941$52d93650$a301280a@.phx.gbl...
>> nvarchar can handle unicode characters
>> varchar cannot
>> if you need to deal with these characters for example
>> french and spanish have accent marks and these are
fairly
>> common within people names and place names, then you
need
>> nvarchar. The downside is that it is twice as large (in
>> storage terms) as varchar because each character
required
>> two bytes, varchar characters require 1 byte.
>> regards & Merry Christmas,
>> Mark Baekdal
>> www.dbghost.com
>> >--Original Message--
>> >Hi everyone,
>> >
>> >Which is better to use for datatypes nvarchar or
varchar?
>> >In access it is a text datatype. For instance i use in
>> access an column with
>> >datatype text, length 100. When upsizing sql server
>> convert this into
>> >nvarchar(100).
>> >
>> >Should i leave it this way or is it better to change
it
>> to a suitable
>> >datatype.
>> >
>> >
>> >.
>> >
>
>.
>

Data type: Text vs VarChar (10000)

I have a table that is used to archive communications.
One of the fields is ComText, I've used the "Text" data type for this field.
Now my question is if I use a varchar data type with the length of (10000) would it improve performance in any way (specialy for reporting purposes)?The maximum row size is less than 8k. Plus, it is not good to have a very long varchar field, the space usage will be poor.|||Thanks for your reply.
Do you have experience regarding this issue and an Access front end, cause it seems to me that access reports have some trobule printing reports with memo fields, specially when the machine has a low RAM.

Data Type varchar and text

I encounter this particular error.

Exception Details:System.Data.SqlClient.SqlException: The data types varchar and text are incompatible in the equal to operator.

Line 21: Dim reader As SqlDataReader = command.ExecuteReader()

This is the first time I'm trying out with MS SQL so I'm abit lost. I hope my code is correct and I've did a little search. I did not set "Text" in my database, I use int and varchar. Here's the affected part of my code and the database.

Dim passwordAs String =""Dim querystringAs String ="SELECT Password FROM Member WHERE Username = @.username"'Dim conn as SqlConnection Using connAs New SqlConnection(ConfigurationManager.ConnectionStrings("mainconnect").ConnectionString)Dim commandAs New SqlCommand(querystring, conn) command.Parameters.Add("@.username", SqlDbType.Text) command.Parameters("@.username").Value = txtLogin.Text conn.Open()Dim readerAs SqlDataReader = command.ExecuteReader()While reader.Read() password = reader("Password").ToString()End While reader.Close()End Using

My database:

User_ID int(4)

Username varchar(50)

Password varchar(255)

Email varchar(50)

Any ideas?

Hi,

line

command.Parameters.Add("@.username", SqlDbType.Text)

should be

command.Parameters.Add("@.username", SqlDbType.VarChar,50)

|||

argh! stupid me.. I forgot about that cause I've been working with MS Access.. Thanks it works!

Sunday, February 19, 2012

Data Type question

Hi
I often have the dilemma of whether to use Text type or Varchar type.
Normally the situation is that the user will input 50 characters however in
some cases he will input 2000 characters should I make the field Text or
Varchar(2000)
Technically the question is whether a varchar field is assigned the space
automatically or only on request also how significant is the overhead of
using the Text type
Thank you in advance,
Shmuel Shulman
SBS Technologies LTD
"S Shulman" <smshulman@.hotmail.com> wrote in message
news:%23vJQVG0nFHA.3380@.TK2MSFTNGP12.phx.gbl...
> Hi
> I often have the dilemma of whether to use Text type or Varchar type.
> Normally the situation is that the user will input 50 characters however
> in some cases he will input 2000 characters should I make the field Text
> or Varchar(2000)
> Technically the question is whether a varchar field is assigned the space
> automatically or only on request also how significant is the overhead of
> using the Text type
>
The "var" in varchar is because the storage is variable. It only takes up
as much space as you use (plus a small fixed overhead).
Using the text type causes a 16-byte locator to be stored in the row instead
of the actual value. The actual value is stored on another page. So the
overhead of using Text is mainly the extra read required to get to the
actual value. For 50-2000 characters, use Varchar.
David
|||Thanks you for your response,
Shmuel
"David Browne" <davidbaxterbrowne no potted meat@.hotmail.com> wrote in
message news:e7rPgN0nFHA.3540@.TK2MSFTNGP10.phx.gbl...
> "S Shulman" <smshulman@.hotmail.com> wrote in message
> news:%23vJQVG0nFHA.3380@.TK2MSFTNGP12.phx.gbl...
> The "var" in varchar is because the storage is variable. It only takes up
> as much space as you use (plus a small fixed overhead).
> Using the text type causes a 16-byte locator to be stored in the row
> instead of the actual value. The actual value is stored on another page.
> So the overhead of using Text is mainly the extra read required to get to
> the actual value. For 50-2000 characters, use Varchar.
> David
>

Data Type question

Hi
I often have the dilemma of whether to use Text type or Varchar type.
Normally the situation is that the user will input 50 characters however in
some cases he will input 2000 characters should I make the field Text or
Varchar(2000)
Technically the question is whether a varchar field is assigned the space
automatically or only on request also how significant is the overhead of
using the Text type
Thank you in advance,
Shmuel Shulman
SBS Technologies LTD"S Shulman" <smshulman@.hotmail.com> wrote in message
news:%23vJQVG0nFHA.3380@.TK2MSFTNGP12.phx.gbl...
> Hi
> I often have the dilemma of whether to use Text type or Varchar type.
> Normally the situation is that the user will input 50 characters however
> in some cases he will input 2000 characters should I make the field Text
> or Varchar(2000)
> Technically the question is whether a varchar field is assigned the space
> automatically or only on request also how significant is the overhead of
> using the Text type
>
The "var" in varchar is because the storage is variable. It only takes up
as much space as you use (plus a small fixed overhead).
Using the text type causes a 16-byte locator to be stored in the row instead
of the actual value. The actual value is stored on another page. So the
overhead of using Text is mainly the extra read required to get to the
actual value. For 50-2000 characters, use Varchar.
David|||Thanks you for your response,
Shmuel
"David Browne" <davidbaxterbrowne no potted meat@.hotmail.com> wrote in
message news:e7rPgN0nFHA.3540@.TK2MSFTNGP10.phx.gbl...
> "S Shulman" <smshulman@.hotmail.com> wrote in message
> news:%23vJQVG0nFHA.3380@.TK2MSFTNGP12.phx.gbl...
> The "var" in varchar is because the storage is variable. It only takes up
> as much space as you use (plus a small fixed overhead).
> Using the text type causes a 16-byte locator to be stored in the row
> instead of the actual value. The actual value is stored on another page.
> So the overhead of using Text is mainly the extra read required to get to
> the actual value. For 50-2000 characters, use Varchar.
> David
>

Data Type question

Hi
I often have the dilemma of whether to use Text type or Varchar type.
Normally the situation is that the user will input 50 characters however in
some cases he will input 2000 characters should I make the field Text or
Varchar(2000)
Technically the question is whether a varchar field is assigned the space
automatically or only on request also how significant is the overhead of
using the Text type
Thank you in advance,
Shmuel Shulman
SBS Technologies LTD"S Shulman" <smshulman@.hotmail.com> wrote in message
news:%23vJQVG0nFHA.3380@.TK2MSFTNGP12.phx.gbl...
> Hi
> I often have the dilemma of whether to use Text type or Varchar type.
> Normally the situation is that the user will input 50 characters however
> in some cases he will input 2000 characters should I make the field Text
> or Varchar(2000)
> Technically the question is whether a varchar field is assigned the space
> automatically or only on request also how significant is the overhead of
> using the Text type
>
The "var" in varchar is because the storage is variable. It only takes up
as much space as you use (plus a small fixed overhead).
Using the text type causes a 16-byte locator to be stored in the row instead
of the actual value. The actual value is stored on another page. So the
overhead of using Text is mainly the extra read required to get to the
actual value. For 50-2000 characters, use Varchar.
David|||Thanks you for your response,
Shmuel
"David Browne" <davidbaxterbrowne no potted meat@.hotmail.com> wrote in
message news:e7rPgN0nFHA.3540@.TK2MSFTNGP10.phx.gbl...
> "S Shulman" <smshulman@.hotmail.com> wrote in message
> news:%23vJQVG0nFHA.3380@.TK2MSFTNGP12.phx.gbl...
>> Hi
>> I often have the dilemma of whether to use Text type or Varchar type.
>> Normally the situation is that the user will input 50 characters however
>> in some cases he will input 2000 characters should I make the field Text
>> or Varchar(2000)
>> Technically the question is whether a varchar field is assigned the space
>> automatically or only on request also how significant is the overhead of
>> using the Text type
> The "var" in varchar is because the storage is variable. It only takes up
> as much space as you use (plus a small fixed overhead).
> Using the text type causes a 16-byte locator to be stored in the row
> instead of the actual value. The actual value is stored on another page.
> So the overhead of using Text is mainly the extra read required to get to
> the actual value. For 50-2000 characters, use Varchar.
> David
>

Data type question

I just had some one ask me about storing PDF files in a SQL table. My
question is, what would the data type be for that column? Is the data type
TEXT the correct one for this?
Thanks to all who can help me.
Billy"BillyDees" <BillyDees@.discussions.microsoft.com> wrote in message
news:F2F96802-6D94-49EC-9720-D7B16C733CBC@.microsoft.com...
>I just had some one ask me about storing PDF files in a SQL table. My
> question is, what would the data type be for that column? Is the data type
> TEXT the correct one for this?
No, PDF is a binary format. Store it in an IMAGE (SQL 2000) or
varbinary(max) (SQL 2005).
David|||Thanks David. I was just talking with a couple co-worker this morning and
they where saying the same thing.
Billy
"David Browne" wrote:
> "BillyDees" <BillyDees@.discussions.microsoft.com> wrote in message
> news:F2F96802-6D94-49EC-9720-D7B16C733CBC@.microsoft.com...
> >I just had some one ask me about storing PDF files in a SQL table. My
> > question is, what would the data type be for that column? Is the data type
> > TEXT the correct one for this?
>
> No, PDF is a binary format. Store it in an IMAGE (SQL 2000) or
> varbinary(max) (SQL 2005).
> David
>
>

Data type of parameter passing to a stored procedure

Hi,
I pass a paramter of text data type in sql server (which crosspnds Memo data type n Access) to a stored procedure but the problem is that I do not know the crossponding DataTypeEnum to Text data type in SQL Server.

The exact error message that occurs is:

ADODB.Parameters (0x800A0E7C)
Parameter object is improperly defined. Inconsistent or incomplete information was provided.

The error occurs in the following code line:
.parameters.Append cmd.CreateParameter ("@.EMedical", advarwchar, adParamInput)

I need to know what to write instead of advarwchar?
Thanks in advance1) memo and varchar isn't the same!
2) you should specify a size for varchar type!
.parameters.Append cmd.CreateParameter ("@.EMedical", advarwchar, adParamInput, 1000)
or other size instead of 1000

Data Type for multi line text?

Hi,
I'm using bulkload to import data from an xml file. The data has several
lines of text before the closing tag. After I bulkload the data all the text
is ran together.
I'm using data type of "Text" on my SQL2005 server, should I use something
else that will keep the formatting? The text can actuall be over several
thousand characters.
Thanks
Charles W
XML format:
<data> Line one with data
Line two with data, a line may be skipped
Fourth line with data.
</data>
SQL format:
Line one with dataLine two with data, a line may be skippedFourth line with
data.
Hello Charles,

> Hi,
> I'm using bulkload to import data from an xml file. The data has
> several
> lines of text before the closing tag. After I bulkload the data all
> the text
> is ran together.
> I'm using data type of "Text" on my SQL2005 server, should I use
> something
> else that will keep the formatting? The text can actuall be over
> several
> thousand characters.
> Thanks
> Charles W
> XML format:
> <data> Line one with data
> Line two with data, a line may be skipped
> Fourth line with data.
> </data>
> SQL format:
> Line one with dataLine two with data, a line may be skippedFourth line
> with
> data.
is nvarchar(max) an option?
Thank you,
Kent Tegels
DevelopMentor
http://staff.develop.com/ktegels/
|||"Charles W" <cwunderlich@.nospam.vrtlweb.com> wrote in message
news:eWjOBAsTGHA.4976@.TK2MSFTNGP11.phx.gbl...
> Hi,
> I'm using bulkload to import data from an xml file. The data has several
> lines of text before the closing tag. After I bulkload the data all the
text
> is ran together.
> I'm using data type of "Text" on my SQL2005 server, should I use something
> else that will keep the formatting? The text can actuall be over several
> thousand characters.
>
> Thanks
> Charles W
>
> XML format:
> <data> Line one with data
> Line two with data, a line may be skipped
> Fourth line with data.
> </data>
> SQL format:
> Line one with dataLine two with data, a line may be skippedFourth line
with
> data.
>
How are you confirmin that the line feeds are actually being removed?
Note that XML will often replace any CRLF sequence with a simple LF.
Could it be that the LFs are there but what you are using to retreive and
display the value requires CRLFs?
Anthony.
|||I thought changing the field to nvarchar(4000) worked, but I ran into a size
problem when processing my files. It seems that some of the data is over the
4000 max.
Any other ideas?
Thanks
CW
"Kent Tegels" <ktegels@.develop.com> wrote in message
news:b87ad741dc7f8c81cab6345f890@.news.microsoft.co m...
> Hello Charles,
>
> is nvarchar(max) an option?
> Thank you,
> Kent Tegels
> DevelopMentor
> http://staff.develop.com/ktegels/
>
|||"Charles W" <cwunderlich@.nospam.vrtlweb.com> wrote in message
news:OxLl6xbUGHA.5500@.TK2MSFTNGP12.phx.gbl...
> I thought changing the field to nvarchar(4000) worked, but I ran into a
size
> problem when processing my files. It seems that some of the data is over
the
> 4000 max.
> Any other ideas?
>
> Thanks
> CW
>
NText is the field type you need. Still doesn't eliminate the Line feed
issue which as already pointed out is not a function of the SQL data type
you are choosing but is just how XML works.
See:-
http://www.w3.org/TR/REC-xml/#sec-line-ends
Anthony

Data Type for multi line text?

Hi,
I'm using bulkload to import data from an xml file. The data has several
lines of text before the closing tag. After I bulkload the data all the text
is ran together.
I'm using data type of "Text" on my SQL2005 server, should I use something
else that will keep the formatting? The text can actuall be over several
thousand characters.
Thanks
Charles W
XML format:
<data> Line one with data
Line two with data, a line may be skipped
Fourth line with data.
</data>
SQL format:
Line one with dataLine two with data, a line may be skippedFourth line with
data.Hello Charles,

> Hi,
> I'm using bulkload to import data from an xml file. The data has
> several
> lines of text before the closing tag. After I bulkload the data all
> the text
> is ran together.
> I'm using data type of "Text" on my SQL2005 server, should I use
> something
> else that will keep the formatting? The text can actuall be over
> several
> thousand characters.
> Thanks
> Charles W
> XML format:
> <data> Line one with data
> Line two with data, a line may be skipped
> Fourth line with data.
> </data>
> SQL format:
> Line one with dataLine two with data, a line may be skippedFourth line
> with
> data.
is nvarchar(max) an option?
Thank you,
Kent Tegels
DevelopMentor
http://staff.develop.com/ktegels/|||"Charles W" <cwunderlich@.nospam.vrtlweb.com> wrote in message
news:eWjOBAsTGHA.4976@.TK2MSFTNGP11.phx.gbl...
> Hi,
> I'm using bulkload to import data from an xml file. The data has several
> lines of text before the closing tag. After I bulkload the data all the
text
> is ran together.
> I'm using data type of "Text" on my SQL2005 server, should I use something
> else that will keep the formatting? The text can actuall be over several
> thousand characters.
>
> Thanks
> Charles W
>
> XML format:
> <data> Line one with data
> Line two with data, a line may be skipped
> Fourth line with data.
> </data>
> SQL format:
> Line one with dataLine two with data, a line may be skippedFourth line
with
> data.
>
How are you confirmin that the line feeds are actually being removed?
Note that XML will often replace any CRLF sequence with a simple LF.
Could it be that the LFs are there but what you are using to retreive and
display the value requires CRLFs?
Anthony.|||I thought changing the field to nvarchar(4000) worked, but I ran into a size
problem when processing my files. It seems that some of the data is over the
4000 max.
Any other ideas?
Thanks
CW
"Kent Tegels" <ktegels@.develop.com> wrote in message
news:b87ad741dc7f8c81cab6345f890@.news.microsoft.com...
> Hello Charles,
>
> is nvarchar(max) an option?
> Thank you,
> Kent Tegels
> DevelopMentor
> http://staff.develop.com/ktegels/
>|||"Charles W" <cwunderlich@.nospam.vrtlweb.com> wrote in message
news:OxLl6xbUGHA.5500@.TK2MSFTNGP12.phx.gbl...
> I thought changing the field to nvarchar(4000) worked, but I ran into a
size
> problem when processing my files. It seems that some of the data is over
the
> 4000 max.
> Any other ideas?
>
> Thanks
> CW
>
NText is the field type you need. Still doesn't eliminate the Line feed
issue which as already pointed out is not a function of the SQL data type
you are choosing but is just how XML works.
See:-
http://www.w3.org/TR/REC-xml/#sec-line-ends
Anthony

Friday, February 17, 2012

Data type conversion issue

Hi guys
I exported some data from a text file to sql server. Here is the sample data..

This table has about 2 million rows.There is a date field in the table which comes as a 'nvarchar' in sql .When i try to convert it to a 'datetime' , i get an error as operation timed out..

Here is the data from the text file...

Date dispensed Outliers Formulation ID Provider Number (dispensing) NSS flag Patient category Units dispensed Total days supply
1/01/2006 12:00:00 a.m. normal 106509.00 7952 I A 120.00 30.00
1/01/2006 12:00:00 a.m. normal 106509.00 8208 I A 360.00 90.00
1/01/2006 12:00:00 a.m. normal 106509.00 9460 I A 120.00 30.00
1/01/2006 12:00:00 a.m. normal 106509.00 10184 I A 120.00 60.00
1/01/2006 12:00:00 a.m. normal 106509.00 10291 I A 120.00 60.00
1/01/2006 12:00:00 a.m. normal 106509.00 11149 I A 120.00 30.00
1/01/2006 12:00:00 a.m. normal 106509.00 11294 I A 120.00 60.00
1/01/2006 12:00:00 a.m. normal 106509.00 11777 I A 120.00 30.00
1/01/2006 12:00:00 a.m. normal 106509.00 12048 I A 120.00 30.00

I have tried the bulk insert as well.

Here is the script for the create table ..

USE [Library]

GO

/****** Object: Table [dbo].[tablename] Script Date: 10/03/2006 14:45:59 ******/

SET ANSI_NULLS ON

GO

SET QUOTED_IDENTIFIER ON

GO

CREATE TABLE [dbo].[NormalOutlier1](

[Datedispensed] [nvarchar](max) COLLATE Latin1_General_CI_AS NULL,

[Outliers] [nvarchar](max) COLLATE Latin1_General_CI_AS NULL,

[Formulation ID] [float] NULL,

[Provider Number (dispensing)] [nvarchar](max) COLLATE Latin1_General_CI_AS NULL,

[NSS flag] [nvarchar](max) COLLATE Latin1_General_CI_AS NULL,

[Patient category] [nvarchar](max) COLLATE Latin1_General_CI_AS NULL,

[Units dispensed] [float] NULL,

[Total days supply] [float] NULL

) ON [PRIMARY]

Hope this helps

Did you try using a datetime rather than NVARCHAR(MAX) in the definition of the table ? There might be a implicit conversion possible for the values. if not you will have to convert the dates with your own logic using either an ETL process in DTS / SSIS or just by using a string manipulation.

HTH, Jens K. Suessmeyer.

http://www.sqlserver2005.de

Data Type ?

Hi Forum, Im new to SQL db and am receiving this error when updating Detailview.

System.Data.SqlClient.SqlException: The data types text and nvarchar are incompatible in the equal to operator.

DB Table PK Customer_ID is set Int also Mobile and PIN columns, all others are Text. Could it be that a combination of text and a number ie 7a 3 MyStreet, be cause?

Detailview Update Parameters as below

<asp:ParameterName="Mobile"Type="Int32"/>

<asp:ParameterName="PIN"Type="Int32"/>

<asp:ParameterName="Street"Type="String"/>

<asp:ParameterName="original_Customer_ID"Type="Int32"/>

Select fills Detailview with Table values OK, its on UPDATE things go wrong! much thanks Paul

Hi pl,

Your trouble is SQL level. You would have to change Text datatype to NVarchar datatype in your columns.

Good Coding!

Javier Luna
http://guydotnetxmlwebservices.blogspot.com/

|||

Don't use the text data type. Change them to varchar(8000) if you must, or use a more realistic number for it's maximum length. If you are using SQL Server 2005 or SQL Express, you can also use varchar(max), which is pretty close to the same thing as text with quite a few less restrictions.

As a side note, it's the sqldatasource that has the problem. Although we don't really need to see it, we can guess what your update statement looks like. It's trying to compare a text field to an original value, and you can't do that. Using text columns for comparision within a WHERE clause isn't allowed.

|||

Thanks for both your replies, changing to column to varchar did the trick!

Something else you could help me with is SQL connection string. Im used to using Access DB, OLEDB

publicString str;

publicstring strAccessConn ="PROVIDER=Microsoft.Jet.OLEDB.4.0;DATA SOURCE=C:\\inetpub\\vhosts\\mtaxi.co.nz\\httpdocs\\data\\mtaxidb1.mdb";

OleDbConnection myAccessConn =newOleDbConnection(strAccessConn);

How to change this toSystem.Data.SqlClient ?

I have connection in web.config

connectionStrings>

<addname="MT_ConnectionString"connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\MTaxidb1.mdf;Integrated Security=True;User Instance=True"

providerName="System.Data.SqlClient" />

</connectionStrings>

SqlConnection myConnection = new SqlConnection("****THIS STRING IM UNSURE OF****");

Really appreciate advice Paul

|||

I'm going to be close, but I don't have the exact code in front of me, but what you want is something similiar to:

SqlConnection myConnection=new SqlConnection(ConfigurationManager.ConnectionStrings("MT_ConnectionString").ConnectionString);

Or you could use this (but obviously it's not configurable then):
SqlConnection myConnection = new SqlConnection("Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\MTaxidb1.mdf;Integrated Security=True;User Instance=True");

|||

Thanks Motely, This has all been good information! helped me out big time cheers P

string incase anyone is interested

strSqlConn = System.Configuration.ConfigurationManager.ConnectionStrings["MT_ConnectionString"].ToString();