Showing posts with label columns. Show all posts
Showing posts with label columns. Show all posts

Friday, March 30, 2012

How to insert numbers from a text box to a Sql database table column’s type numeric?

Hi,

I am getting an error when I try to insert a number typed in a text box control into a Sql database table column's type numeric(6,2). For example: If I type 35,22 into the text box, or 35, and then I submit the form to insert the data into database, I get the follow error:

System.FormatException: Input string was not in a correct format.
Line 428: CmdInsert.Parameters.Add(New SqlParameter("@.Measure", SqlDbType.decimal, "Measure"))

A piece of the SP inside Sql server:


USE market26
GO
ALTER PROC new_offer
@.Offer_id bigint, @.Measure numeric(6,2) = null, …

What is wrong? Why it doesn' t accept the number typed in my text box?

Thank you,
CesarThis is not correct:


CmdInsert.Parameters.Add(New SqlParameter("@.Measure", SqlDbType.Decimal, "Measure"))

This would probably work (not tested):


SqlParameter mParm = new SqlParameter("@.measure", SqlDbType.Decimal);
mParm.Size = 13; // Max size in Bytes of the Decimal number
mParm.Precision = 8; // Total number of digits allowed (right + left of decimal point
mParm.Scale = 2; // Set the number of decimal places the Parameter value is resolved
mParm.set_IsNullable(true);
mParm.Value = decimal.Parse(myTextBox.Text.Trim());

CmdInsert.Parameters.Add(mParm)

|||Hi,

I always write my ASP.NET commands to talk with Sql Stored Procedures thus:


CmdInsert.Parameters.Add(New SqlParameter("@.Measure", SqlDbType.Decimal, "Measure"))

I think that it is correct, and it works fine.

I have never used a text field to insert numeric data into Sql database, but, I have to define all these parameter properties in order to pass a numeric data type to the database?

Thanks|||That's interesting. There is no Constructor attributed to the SqlParameter Class which accepts a Constructor looking like this:


New SqlParameter(<string>,<SqlDbType Enum>, <string>)

as far as I know...But hey, go for it!|||Take a look at this piece of an article and let me know what do you think about it:


Dim sConnectionString As String = _
"server=localhost;uid=sa;pwd=;database=Northwind"
Dim cnNorthwind As New SqlConnection(sConnectionString)
Dim cmdOrders As New SqlCommand("CustOrderHist", cnNorthwind)
cmdOrders.CommandType = CommandType.StoredProcedure
' Set up parameter for stored procedure
Dim prmCustomerID As New SqlParameter()
prmCustomerID.ParameterName = "@.CustomerID"
prmCustomerID.SqlDbType = SqlDbType.VarChar
prmCustomerID.Size = 5
prmCustomerID.Value = "ALFKI"

cmdOrders.Parameters.Add(prmCustomerID)

Dim daGetOrders As New SqlDataAdapter(cmdOrders)
Dim dsOrders As New DataSet()
daGetOrders.Fill(dsOrders, "Orders")
DataGrid1.DataSource = dsOrders.Tables("Orders")


This example makes all the parameter settings explicit. Some developers like this style, and it's good for instructional purposes. However, some developers prefer an equivalent alternative that has fewer lines of code:

Dim sConnectionString As String = _
"server=localhost;uid=sa;pwd=;database=Northwind"
Dim cnNorthwind As New SqlConnection(sConnectionString)
Dim cmdOrders As New SqlCommand("CustOrderHist", cnNorthwind)
cmdOrders.CommandType = CommandType.StoredProcedure

cmdOrders.Parameters.Add(New _
SqlParameter("@.CustomerID", SqlDbType.VarChar, 5))
cmdOrders.Parameters("@.CustomerID").Value = "ALFKI"

Dim daGetOrders As New SqlDataAdapter(cmdOrders)
Dim dsOrders As New DataSet()
daGetOrders.Fill(dsOrders, "Orders")
DataGrid1.DataSource = dsOrders.Tables("Orders")


This code behaves exactly the same as the previous example. However, it only needs two lines of code for each parameter rather than six. When a stored procedure has a lot of parameters (as some of our later examples do), this can be quite a difference on lines of code required, so we'll use that form from this point onward.

The complete article is here: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnadvnet/html/vbnet09102002.asp|||Hey! Perhaps you have misunderstood me. I meant that I always use this structure:
(Which I knew that something was wrong)


CmdInsert.Parameters.Add(New SqlParameter("@.Measure", SqlDbType.Decimal, "Measure"))

Instead of this:

SqlParameter mParm = new SqlParameter("@.measure", SqlDbType.Decimal)
mParm.SourceColumn = "Measure"
CmdInsert.Parameters.Add(mParm)

I knew that something was wrong, I suspected that something it lacked in my SqlParameter, and you helped me with your example!, it lacked only the size property which in my case is 5. I am sorry, the only thing that I saw strange is the structure you wrote, and the amount of parameters which I don' t need to use (in this case). I always use the shorter alternative ;-).

So, the correct SqlParameter in my case is:


CmdInsert.Parameters.Add(New SqlParameter("@.Measure", SqlDbType.Decimal,5, "Measure"))

And now works fine.
Thank you very much!
Cesar

How to insert NULL when using bcp_moretext?

How do you insert a NULL value when using bcp_moretext?
If I have a table with two 'text' or 'image' columns, and I am using bcp_mor
etext to insert a very large LOB into one of them, then BCP requires that I
use bcp_moretext for both of them ("use it for one 'text'/'image', then must
use it for all").
(In fact, I've discovered that I can bcp_bind a NULL with a non-NULL vardata
address for earlier 'text'/'image', but once I bcp_bind a NULL vardata, ind
icating my wish to use bcp_moretext, then all following 'text'/'image' colum
ns in ordinal order must al
so be bound with a NULL vardata -- i.e. once you use bcp_moretext for a 'tex
t'/'image', it's really all *following* that must be also sent with bcp_more
text. At least that's the behavior I see.)
I'm using the SQL Server 7 ODBC driver extensions (rather than 6.5 DB-LIB BC
P). Setting the param length to zero (bcp_bind or bcp_collen) for 7.0 BCP te
lls it that you are sending a zero-length param. You still need to call bcp_
moretext later with length
0, for that column. Setting length to SQL_NULL_DATA will cause an error late
r, whether you try to call bcp_moretext with length SQL_NULL_DATA, with leng
th 0, or try to skip calling bcp_moretext for this column.
I don't believe it's possible to send NULL, via BCP, to a 'text' or 'image'
column, once you've sent 0 or >0 length data to any earlier (in ordinal orde
r) 'text' or 'image' column using bcp_moretext. But, I would like Microsoft
to verify this, since the d
ocumentation doesn't cover this at all.
Thanks,
Jim FloodCan I expect some sort of response from Microsoft in this group within two d
ays, as part of the benefit of my MSDN subscription?
-- Jim Flood wrote: --
How do you insert a NULL value when using bcp_moretext?
If I have a table with two 'text' or 'image' columns, and I am using bcp_mor
etext to insert a very large LOB into one of them, then BCP requires that I
use bcp_moretext for both of them ("use it for one 'text'/'image', then must
use it for all").
(In fact, I've discovered that I can bcp_bind a NULL with a non-NULL vardata
address for earlier 'text'/'image', but once I bcp_bind a NULL vardata, ind
icating my wish to use bcp_moretext, then all following 'text'/'image' colum
ns in ordinal order mu
st also be bound with a NULL vardata -- i.e. once you use bcp_moretext for a
'text'/'image', it's really all *following* that must be also sent with bcp
_moretext. At least that's the behavior I see.)
I'm using the SQL Server 7 ODBC driver extensions (rather than 6.5 DB-LIB BC
P). Setting the param length to zero (bcp_bind or bcp_collen) for 7.0 BCP te
lls it that you are sending a zero-length param. You still need to call bcp_
moretext later with le
ngth 0, for that column. Setting length to SQL_NULL_DATA will cause an error
later, whether you try to call bcp_moretext with length SQL_NULL_DATA, with
length 0, or try to skip calling bcp_moretext for this column.
I don't believe it's possible to send NULL, via BCP, to a 'text' or 'image'
column, once you've sent 0 or >0 length data to any earlier (in ordinal orde
r) 'text' or 'image' column using bcp_moretext. But, I would like Microsoft
to verify this, since
the documentation doesn't cover this at all.
Thanks,
Jim Flood|||I'm checking with our BCP guy.
Brannon Jones
Developer - MDAC
This posting is provided "as is" with no warranties and confers no rights.
"Jim Flood" <bezspam@.bezspam.cz> wrote in message
news:C95C8F5A-BF58-48F3-A516-AC5980947BDE@.microsoft.com...
> Can I expect some sort of response from Microsoft in this group within two
days, as part of the benefit of my MSDN subscription?
> -- Jim Flood wrote: --
> How do you insert a NULL value when using bcp_moretext?
> If I have a table with two 'text' or 'image' columns, and I am using
bcp_moretext to insert a very large LOB into one of them, then BCP requires
that I use bcp_moretext for both of them ("use it for one 'text'/'image',
then must use it for all").
> (In fact, I've discovered that I can bcp_bind a NULL with a non-NULL
vardata address for earlier 'text'/'image', but once I bcp_bind a NULL
vardata, indicating my wish to use bcp_moretext, then all following
'text'/'image' columns in ordinal order must also be bound with a NULL
vardata -- i.e. once you use bcp_moretext for a 'text'/'image', it's really
all *following* that must be also sent with bcp_moretext. At least that's
the behavior I see.)
> I'm using the SQL Server 7 ODBC driver extensions (rather than 6.5
DB-LIB BCP). Setting the param length to zero (bcp_bind or bcp_collen) for
7.0 BCP tells it that you are sending a zero-length param. You still need to
call bcp_moretext later with length 0, for that column. Setting length to
SQL_NULL_DATA will cause an error later, whether you try to call
bcp_moretext with length SQL_NULL_DATA, with length 0, or try to skip
calling bcp_moretext for this column.
> I don't believe it's possible to send NULL, via BCP, to a 'text' or
'image' column, once you've sent 0 or >0 length data to any earlier (in
ordinal order) 'text' or 'image' column using bcp_moretext. But, I would
like Microsoft to verify this, since the documentation doesn't cover this at
all.
> Thanks,
> Jim Flood|||Hello Brannon,
Have you heard back about the BCP problem yet? Is there anything else I need
to do besides post to this group, to get the two-day response from Microsof
t? It's been well over two days.
Thanks,
Jim Flood|||Hi Jim,
I've faced the same problem. I can't insert NULLs using bcp_moretext.
Have you found a solution?
Thanks in advance,
Alberto.
"Jim Flood" <anonymous@.discussions.microsoft.com> escribi en el mensaje
news:0BB0853D-430D-4299-88D2-7343C6C024A8@.microsoft.com...
> How do you insert a NULL value when using bcp_moretext?
> If I have a table with two 'text' or 'image' columns, and I am using
bcp_moretext to insert a very large LOB into one of them, then BCP requires
that I use bcp_moretext for both of them ("use it for one 'text'/'image',
then must use it for all").
> (In fact, I've discovered that I can bcp_bind a NULL with a non-NULL
vardata address for earlier 'text'/'image', but once I bcp_bind a NULL
vardata, indicating my wish to use bcp_moretext, then all following
'text'/'image' columns in ordinal order must also be bound with a NULL
vardata -- i.e. once you use bcp_moretext for a 'text'/'image', it's really
all *following* that must be also sent with bcp_moretext. At least that's
the behavior I see.)
> I'm using the SQL Server 7 ODBC driver extensions (rather than 6.5 DB-LIB
BCP). Setting the param length to zero (bcp_bind or bcp_collen) for 7.0 BCP
tells it that you are sending a zero-length param. You still need to call
bcp_moretext later with length 0, for that column. Setting length to
SQL_NULL_DATA will cause an error later, whether you try to call
bcp_moretext with length SQL_NULL_DATA, with length 0, or try to skip
calling bcp_moretext for this column.
> I don't believe it's possible to send NULL, via BCP, to a 'text' or
'image' column, once you've sent 0 or >0 length data to any earlier (in
ordinal order) 'text' or 'image' column using bcp_moretext. But, I would
like Microsoft to verify this, since the documentation doesn't cover this at
all.
> Thanks,
> Jim Flood|||Hello Alberto,
If all of your NULLs are lined up contiguous to the left in the set of colum
ns for a given row, then just avoid bcp_moretext for those columns -- althou
gh, according to the documentation, this isn't supposed to work. But, once y
ou've set bcp_moretext for
a column, going left-to-right, then all other columns to the right will have
to be bcp_moretext'ed as well, and then you can't set any of them to NULL.
So, I have no solution.
Can I please get some kind of response from Microsoft on this problem? I bel
ieve my MSDN subscription should guarantee a two-day response time, and it h
as been *far* more than two days.
Jim Flood

Wednesday, March 28, 2012

How to insert a zero length string into a field using SqlDataSource?

I have a few columns in table with default value defined as zero length string (''). I want to insert record from DetailsView which uses SqlDataSource as DataSource. In the ItemInserting event, if the data is not valid, I want to use zero length string for the column. But I always get Null instead of zero length string. The code in ItemInserting event looks like this:

If objddl.SelectedIndex > 0 Then
e.Values("myFld") = objddl.SelectedItem.Value
Else
e.Values("myFld") = ""
End If

The line: e.Values("myFld") = "" put Null in the column.

How can I set a column as zero length string using the SqlDataSource?

Any help is appreciated.

Thanks.

Try:

e.Values("myFld") =string.Empty

|||Check the advanced properties of the parameter in your upate statement. You probably have the property (Sorry, the exact name eludes me) "ChangeEmptyStringToNull" set to true (true is the default).|||Thank you very much. "ConvertEmptyStringToNull" worked perfectly.

Monday, March 26, 2012

how to insert identity values

hi to the group,
i am small problem,
i am having two columns 1 is col1 which is a primary key and col2 any think .now i want to insert the data into second column at that time the first column must get the values in identity (like 1,2,3,4 etc)
with out using identity(sql server)/generated always(db2)
can any one knows please explain itDidn't I answer this one already?

http://weblogs.sqlteam.com/brettk/archive/2004/06/29/1687.aspx|||Didn't I answer this one already?

http://weblogs.sqlteam.com/brettk/archive/2004/06/29/1687.aspx
OMFG brett, are you kidding?

you seriously expect people to remember everything you wrote up to several years ago on a completely different site from this one?

i don't know, man, did you answer it already?

sheesh|||jagadish, look up the SET IDENTITY INSERT option in Books Online.

How to index through columns

How do you index through a set of Columns Programmatically using SQL. I have a Table all the columns have the same data for different dates. Column names are Col_0, Col_1, Col_2,....Col_100, Col_101. I need to perform the same calculation on each column to manipulate the data into a different table. Is it possible to do a While loop that changes the Column name in a SELECT statement. I have tried to do this but can't seem to get it to work. Please help !

You could set up a cursor using syscolumns.

Run this in QA after changing the table name:

select colid, name
from syscolumns
where id = (
select id
from sysobjects
where name = 'MyTableName')
order by colid

That should give you an idea of how to use that. You can dynamically build SQL using your cursor and execute it. There may be something more elegant, but I've used this successfully in the past.

|||Thank PDraigh I will try it

How to Index through a tables Columns

I am trying to index through the columns of MyTable so I can do the same work on all columns. I know how to get the column names from MyTable but when I use @.MyColName in the SELECT statement to get MyTable Column 0 Row values I get a table with the column name in each row cell. I can't get the syntax correct to return the value in each cell for that column.

This is a extremely simplified example !!!!!!
DECLARE @.MyColName nvarchar(30)

--Get the MyTable Column 0 Name
SELECT @.MyColName = Col_Name(Object_ID('MyTable'), 0)

--Display the MyTable Column 0 Row values
SELECT @.MyColName FROM MyTable --This is the syntax I can not get correct

Can anyone help ?

Thanks

You can't use a variable for a column name; you will have to usedynamic SQL to meet your goal. Build the SQL statement in avariable and then EXECUTE it, like this:
DECLARE @.MySQLStatement varchar(500)
SELECT @.MySQLStatement = 'SELECT ' + @.MyColName + ' FROM MyTable'
EXECUTE(@.MySQLStatement)


|||

tmorton

Thanks for your responce, I will give it a try.

Wednesday, March 21, 2012

How to improve this query?

Aliquot table contains columns PatientID, AliquotTypeID, LocationCode,
AliquotNumber. The query is to get the locationCode with minimum
AliquotNumber in a (PatientID and AliquotTypeID) Group.
select locationCode from aliquot a
where a.patientID = 1 and aliquotTypeID = 1 and
a.aliquotNumber = (Select min(aliquotNumber) from aliquot where patientID =
1 and aliquotTypeID= 1 and locationCode is not null)
thanks,Try:
SELECT LOCATIONCODE, MIN(ALIQUOTNUMBER)
FROM ALIQUOT
WHERE PATIENTID = 1 AND ALIQUOTTYPEID = 1 AND LOCATIONCODE IS NOT NULL
GROUP BY LOCATIONCODE
HTH
Jerry
"Caspy" <caspases@.yahoo.com> wrote in message
news:O2fa1rQyFHA.700@.TK2MSFTNGP11.phx.gbl...
> Aliquot table contains columns PatientID, AliquotTypeID, LocationCode,
> AliquotNumber. The query is to get the locationCode with minimum
> AliquotNumber in a (PatientID and AliquotTypeID) Group.
> select locationCode from aliquot a
> where a.patientID = 1 and aliquotTypeID = 1 and
> a.aliquotNumber = (Select min(aliquotNumber) from aliquot where patientID
> = 1 and aliquotTypeID= 1 and locationCode is not null)
> thanks,
>
>|||Thanks for your reply. Because the locationCode is unique for each
AliquotNumber, your query returns multiple rows.
Since the Aliquot table has half million tupples, I just want to limit to 1
visit to this big table when try to retrieve the locationCode with minimum
aliquotNumber in a (patientID and AliquotTypeID) group.
"Jerry Spivey" <jspivey@.vestas-awt.com> wrote in message
news:%23lXiB3QyFHA.1256@.TK2MSFTNGP09.phx.gbl...
> Try:
> SELECT LOCATIONCODE, MIN(ALIQUOTNUMBER)
> FROM ALIQUOT
> WHERE PATIENTID = 1 AND ALIQUOTTYPEID = 1 AND LOCATIONCODE IS NOT NULL
> GROUP BY LOCATIONCODE
> HTH
> Jerry
> "Caspy" <caspases@.yahoo.com> wrote in message
> news:O2fa1rQyFHA.700@.TK2MSFTNGP11.phx.gbl...
>

Monday, March 12, 2012

How to Import from flat file and update DateTime column?

I have a a flat file that consists of 2 Columns of data that need to overwrite an existing Table that has 3 Columns of data. The Import fails because the 3rd column on the table is a Date stamp column with the Data Type of "smalldatetime" and does not allow Null data. If I were to delete this 3rd column from the table the import works great but I lose the DateTime column. How can I use the Import Wizard to import the first 2 columns from a text file and update the 3rd column with the date and time? The wizard does not seem to let me update a column unless the data for this column comes from the flat file. Please assist, thanx.

Which wizard are you talking about? The import / export data wizard? If so this wizard is for appending new rows or deleting existing rows. I do not believe that it is really meant for updating rows (i.e. overwriting). You would want to create an SSIS package and use the OLE DB Command instead of the OLE DB Source to overwrite a row.

|||

If you are looking to import data, you can use the wizard to build the package, then save it and open it in Business Intelligence Developer Studio. If you then open the data flow, you can add a Derived Column task, add a new column to it, and use the GETDATE() function to return the current date.

|||If he did what you suggest wouldn't he still just be importing new records instead of overwriting the existing records?

|||

I believe the import/export wizard gives you the ability of providing a query for the import. Perhaps you can write a where you have a 3rd columns with the getdate(if using sql server) or sysdate(for Oracle) or any other DB function that retrieves the current date.

|||From his description, I wasn't positive that he wanted to "update" existing records as much as he was looking to truncate and reload the table. Using the wizard (and setting the create destination table options) will drop and recreate the table before loading it. However, I might have his needs wrong. Maybe he'll respond and let us know if either approach was successful.

|||

I'm sure the OP will realise that when the going gets tough, the tough-SSIS-community-contributors get going.

Sorry.

How to import fixed-width text file in MS SQL 2000?

Hello,
Is there a simple answer to this simple question?
How to import fixed-width text file?
I know the width of the columns but there are so many that I don't want
redefine them. I have already a table build for that data with the necessary
fields width. In dbase it was such a simple thing to do...
Note:
I went through the Import wizard in MS SQL 2000 and I could not find any
thing there about importing fixed-width text file.
Any help is greatly appreciated,
Les
> Note:
> I went through the Import wizard in MS SQL 2000 and I could not find any
> thing there about importing fixed-width text file.
The wizard does not have the option to use the Bulk Insert DTS task. The DTS
Bulk Insert task gives you graphical interface. Check it in Books OnLine if
it suits you.
Dejan Sarka, SQL Server MVP
Associate Mentor
www.SolidQualityLearning.com
|||Bulk insert with a format file?
http://www.mindsdoor.net/SQLTsql/BCP...rmat_file.html
Bulk insert with a staging table?
http://www.mindsdoor.net/SQLTsql/ImportTextFiles.html
You can generate the format file for the first one or the inser statement in
the second from the structure of the destination table if you have set the
column sizes to match the file.
If you have a lot of different files consider holding the metadata in a table
http://www.mindsdoor.net/SQLTsql/MoveImportData.html
"Tom" wrote:

> Hello,
> Is there a simple answer to this simple question?
> How to import fixed-width text file?
> I know the width of the columns but there are so many that I don't want
> redefine them. I have already a table build for that data with the necessary
> fields width. In dbase it was such a simple thing to do...
> Note:
> I went through the Import wizard in MS SQL 2000 and I could not find any
> thing there about importing fixed-width text file.
>
> Any help is greatly appreciated,
> Les
>
>

How to import fixed-width text file in MS SQL 2000?

Hello,
Is there a simple answer to this simple question?
How to import fixed-width text file?
I know the width of the columns but there are so many that I don't want
redefine them. I have already a table build for that data with the necessary
fields width. In dbase it was such a simple thing to do...
Note:
I went through the Import wizard in MS SQL 2000 and I could not find any
thing there about importing fixed-width text file.
Any help is greatly appreciated,
LesThis can be done through the DTS import wizard in Enterprise Manager under
Tools --> Data Transformation Services --> Import Data.
In the wizard select the source Data Source as 'Text File'. The wizard will
guide you through the steps.
Alternative methods to DTS are the bcp utility and the 'BULK INSERT'
command.
--
Stuart Fish
www.technologic.co.nz
"Tom" <tom@.killspam.com> wrote in message
news:M0UGd.14491$W33.456289@.news20.bellglobal.com...
> Hello,
> Is there a simple answer to this simple question?
> How to import fixed-width text file?
> I know the width of the columns but there are so many that I don't want
> redefine them. I have already a table build for that data with the
> necessary fields width. In dbase it was such a simple thing to do...
> Note:
> I went through the Import wizard in MS SQL 2000 and I could not find any
> thing there about importing fixed-width text file.
>
> Any help is greatly appreciated,
> Les
>|||I've tried that and it and I found that through the wizard you have to
define the length of the fields.
But I have already a table with the fields. I don't want to go through 50
fields every time I want to import data.
Is that all what we pay MS for?
Les
"Stuart Fish" <stuart@.fish._no__spam_.net.nz> wrote in message
news:u7PwA4M$EHA.2316@.TK2MSFTNGP15.phx.gbl...
> This can be done through the DTS import wizard in Enterprise Manager under
> Tools --> Data Transformation Services --> Import Data.
> In the wizard select the source Data Source as 'Text File'. The wizard
> will guide you through the steps.
> Alternative methods to DTS are the bcp utility and the 'BULK INSERT'
> command.
>
> --
> --
> Stuart Fish
> www.technologic.co.nz
>
> "Tom" <tom@.killspam.com> wrote in message
> news:M0UGd.14491$W33.456289@.news20.bellglobal.com...
>> Hello,
>> Is there a simple answer to this simple question?
>> How to import fixed-width text file?
>> I know the width of the columns but there are so many that I don't want
>> redefine them. I have already a table build for that data with the
>> necessary fields width. In dbase it was such a simple thing to do...
>> Note:
>> I went through the Import wizard in MS SQL 2000 and I could not find any
>> thing there about importing fixed-width text file.
>>
>> Any help is greatly appreciated,
>> Les
>>
>|||At the end of the DTS Import/Export wizard there are options that allow you
to save the DTS package instead of running immediately. That way the DTS
package can then be executed or scheduled as you need it. You don't need to
redefine it each time, as long as your file and table structure remain the
same.
If the package is saved to the SQL Server it can be viewed in Enterprise
Manager under the Data Transformations Services --> Local Packages folder.
"Tom" <tom@.killspam.com> wrote in message
news:sOUGd.15394$W33.466935@.news20.bellglobal.com...
> I've tried that and it and I found that through the wizard you have to
> define the length of the fields.
> But I have already a table with the fields. I don't want to go through 50
> fields every time I want to import data.
> Is that all what we pay MS for?
> Les
>
> "Stuart Fish" <stuart@.fish._no__spam_.net.nz> wrote in message
> news:u7PwA4M$EHA.2316@.TK2MSFTNGP15.phx.gbl...
>> This can be done through the DTS import wizard in Enterprise Manager
>> under Tools --> Data Transformation Services --> Import Data.
>> In the wizard select the source Data Source as 'Text File'. The wizard
>> will guide you through the steps.
>> Alternative methods to DTS are the bcp utility and the 'BULK INSERT'
>> command.
>>
>> --
>> --
>> Stuart Fish
>> www.technologic.co.nz
>>
>> "Tom" <tom@.killspam.com> wrote in message
>> news:M0UGd.14491$W33.456289@.news20.bellglobal.com...
>> Hello,
>> Is there a simple answer to this simple question?
>> How to import fixed-width text file?
>> I know the width of the columns but there are so many that I don't want
>> redefine them. I have already a table build for that data with the
>> necessary fields width. In dbase it was such a simple thing to do...
>> Note:
>> I went through the Import wizard in MS SQL 2000 and I could not find any
>> thing there about importing fixed-width text file.
>>
>> Any help is greatly appreciated,
>> Les
>>
>>
>|||Les,
Most of people choose to loading the data from import file in to a temporary table then doing manipulation on that temp table, this way is useful when during the import progress, you could also maintain your database integrity.
to solve your problem, you could you DTS or SQL stored procedure. i was selected stored procedure to manage this process.
e.g:
you have list of invoice need to be imported to invoice table every day. this file is a flat fixed length file storing in following desc
Invoice#ProductCategory
xxxx-xxxAAAAAAAACCCCCCCC
length of row was 24, since Invoice# was 8, Product 8, Category 8. This file name is invoice.txt
you could define a table as follow
INVOICE_TEMP(
ROWTMP VARCHAR(24)
)
In you stored procedure, you would have this command
BULK INSERT INVOICE_TEMP FROM invoice.txt WITH (BATCHSIZE = 10000, CODEPAGE ='RAW', ROWTERMINATOR = '\n')
Next: You could be able to insert the rows from this temp file to destination table.
INSERT INVOICE (InvoiceNo, Product, Category)
SELECT SUBSTRING(ROWTMP, 1, 8), SUBSTRING(ROWTMP, 1, 8), SUBSTRING(ROWTMP, 1, 8) FROM INVOICE_TEMP
*done*.
Next: your stored procedure could be called any time you want, or it could be called from DTS and have it running in a defined schedule.
Good luck!
Doan
--
Message posted via http://www.sqlmonster.com

How to import Data from Excel to SQL Server Express

Hi,
please any one is expert in Data Base help me, i would like to import two Data columns from Excel file 2003 instead of two columns in a table in Sql Server Express 2005 , How Can i do that? and what is the way if I have Sql Developer 2005, thank you .

Your query is not clear.. you wish to copy data from Excel to SQL Server Express or You wish to read Excel data from ASP.Net application:

If you want to know, how to read Excel data in ASP.Net Application, visit the follocing web link:

http://weblogs.asp.net/scottgu/archive/2006/05/29/Reading_2F00_Writing-Excel-Spreadsheets-with-ADO.NET.aspx

|||

Hi,

You may try this SQL fonction OPENROWSET, suppose you have an Excel file in the C:\ drive of the SQL Server database, and the data is on a Worksheet called Sheet1 and your two columns are called Column1 and Column2.

INSERT INTO MyTable
SELECT Column1, Column2
FROM OPENROWSET('Microsoft.Jet.OLEDB.4.0',
'Excel 8.0;Database=C:\MyTable.xls',
'SELECT * FROM [Sheet1$]')
 
The first row of your Excel file should coutains the colums names.
 Hope this answer your question. 
Dominic 

|||

hi, exactly i would like to copy two columns of data from Excel file instead of two columns of data in sql express,thank u

Wednesday, March 7, 2012

How to implement this case?

Hi,

I want the select result 1 record show 1 image but not use table or list, how could I do?

More...

The select result has 2 columns, "Org" and "Image".

"Org" is orgainzation and "Image" save the image, its data type is image.

After select, the record like this

Org Image

2211 000C10000BB0000B30000A..
2212 1FFFC2AFFFF39FFFF3FFFF..
2213 000C10000BB0000B30000A..
2214 ...
...

Every record show its own image, how can I implement it?

Thanks!

can you give more information!!

i think that you can use the table report items in reporting service

|||

Dear ,

Drop the image control on the report desinger and check how to get he image from the database.

In the image wizard u will get the option to get image from the database.

HTH

from

sufian

How to implement floating headers and/or columns

Hello,
I have read in a number of Powerpoint presentation from MS folks that we
have the ability to implement floating headers and/or column, similar to
freezing panes in Excel.
Could somebody please point me to the article/link that explains how to
implement this?
Thanks in advance for your help,
Ashok GThis is only available in SQL Reporting Services 2005.
http://groups.google.com/group/microsoft.public.sqlserver.reportingsvcs/browse_frm/thread/5b282ff53c37b672/a5fcf4b22a3766f7?q=fixed+header&rnum=1#a5fcf4b22a3766f7
Andy Potter|||Thanks Andy. Appreciate your response. I was also looking for floating
columns. Please do let me know if youhave further information.
--
Thank you,
Ashok G
"Potter" wrote:
> This is only available in SQL Reporting Services 2005.
> http://groups.google.com/group/microsoft.public.sqlserver.reportingsvcs/browse_frm/thread/5b282ff53c37b672/a5fcf4b22a3766f7?q=fixed+header&rnum=1#a5fcf4b22a3766f7
> Andy Potter
>|||Does this work the same when a report renders to Excel?
I am wondering if this freezes the table header in Excel? so that it prints
out the table header row in every page in Excel and the table header stays
when the user scroll down to the bottom of the report.
Thanks!
"Potter" wrote:
> This is only available in SQL Reporting Services 2005.
> http://groups.google.com/group/microsoft.public.sqlserver.reportingsvcs/browse_frm/thread/5b282ff53c37b672/a5fcf4b22a3766f7?q=fixed+header&rnum=1#a5fcf4b22a3766f7
> Andy Potter
>

Sunday, February 19, 2012

How to hide table columns for users without permission in SQL Tool

Hi,
I already set select permission to certain columns in a table for a user.
BUt the user still can view all the columns in the Enterprise Manager/ SQL
Mgt Studio. HOw to hide those columns without permission ?
Hi
If restrict access to the table by use stored procedures then the user does
not need permissions on the table directly. You can also be granular to
column level what permissions are granted.
Not giving them access to Enterprise Manager may also be an idea.
John
"Wan" wrote:

> Hi,
> I already set select permission to certain columns in a table for a user.
> BUt the user still can view all the columns in the Enterprise Manager/ SQL
> Mgt Studio. HOw to hide those columns without permission ?
|||Hi
Just to add, you may not exclude the user seeing the existance of the column
even if you have denied them permissions to see the data.
John
"John Bell" wrote:
[vbcol=seagreen]
> Hi
> If restrict access to the table by use stored procedures then the user does
> not need permissions on the table directly. You can also be granular to
> column level what permissions are granted.
> Not giving them access to Enterprise Manager may also be an idea.
> John
> "Wan" wrote:

How to hide table columns for users without permission in SQL Tool

Hi,
I already set select permission to certain columns in a table for a user.
BUt the user still can view all the columns in the Enterprise Manager/ SQL
Mgt Studio. HOw to hide those columns without permission ?Hi
If restrict access to the table by use stored procedures then the user does
not need permissions on the table directly. You can also be granular to
column level what permissions are granted.
Not giving them access to Enterprise Manager may also be an idea.
John
"Wan" wrote:
> Hi,
> I already set select permission to certain columns in a table for a user.
> BUt the user still can view all the columns in the Enterprise Manager/ SQL
> Mgt Studio. HOw to hide those columns without permission ?|||Hi
Just to add, you may not exclude the user seeing the existance of the column
even if you have denied them permissions to see the data.
John
"John Bell" wrote:
> Hi
> If restrict access to the table by use stored procedures then the user does
> not need permissions on the table directly. You can also be granular to
> column level what permissions are granted.
> Not giving them access to Enterprise Manager may also be an idea.
> John
> "Wan" wrote:
> > Hi,
> > I already set select permission to certain columns in a table for a user.
> > BUt the user still can view all the columns in the Enterprise Manager/ SQL
> > Mgt Studio. HOw to hide those columns without permission ?

How to hide table columns for users without permission in SQL Tool

Hi,
I already set select permission to certain columns in a table for a user.
BUt the user still can view all the columns in the Enterprise Manager/ SQL
Mgt Studio. HOw to hide those columns without permission ?Hi
If restrict access to the table by use stored procedures then the user does
not need permissions on the table directly. You can also be granular to
column level what permissions are granted.
Not giving them access to Enterprise Manager may also be an idea.
John
"Wan" wrote:

> Hi,
> I already set select permission to certain columns in a table for a user.
> BUt the user still can view all the columns in the Enterprise Manager/ SQ
L
> Mgt Studio. HOw to hide those columns without permission ?