insert into scn_transaction (sourceSystemName) values(@sourceSystem);
SELECT @txOut = @@identity
Whose purpose is to perform an insert into a table and return me the identity value of the inserted record, which I'll then use throughout the rest of my package. The identity column in the inserted table is numeric(18,0).
I execute the stored proc with the following sql with an OLE DB connection manager:
exec sp_newTransaction ?, ?
The first parameter is a string variable from earlier in the package, and the second is the output parameter. I have the following parameter mappings to the execute sql task:
The proc is correctly called, and the row insesrted, however I get a type conversion error when SSIS attempts to map the return parameter to my package variable... I've tried all sorts of combonations, and can't seem to get it to execute.
At one point I wasn't returning a numeric, but rather an int from the stored proc, and all was well until I went to use the variable in a derived column later in the package, and the type was converted quite incorrectly (a 1 was 77799789080 or some such), indicating a type conversion error likely related to the encoding of the number.
I'd like to keep the datatypes as numeric and make ssis use those - any pointers are greatly appreciated as to what type my package variable should be to allow proper assignment of a sql server numeric type to it.
I'm using varchar as a datatype and my leading zeros are chopped-off once ther data reaches my Stored Proc. The table will allow me to store the values with leading zeros if I enter them manually, but I cannot insert them via ASP/StoredProc.
I am putting a SELECT statement together where I need to evaluate a results field, to determine how the color indicator will show on a SSRS report. I am running into a problem when I try to filter out any non-numeric values from a varchar field, using a nested CASE statement.
For example, this results field may contain values of '<1', '>=1', '1', '100', '500', '5000', etc. For one type of test, I need a value of 500 or less to be shown as a green indicator in a report, and any value over that would be flagged as a red. Another test might only allow a value of 10 or less before being flagged with a red.
This is why I setup a CASE statement for an IndicatorValue that will pass over to the report to determine the indicator color. Using CASE statements for this is easier to work with, and less taxing on the report server, if done in SQL Server instead of nested SSRS expressions, especially since a variety of tests have different result values that would be flagged as green or red.
I have a separate nested CASE statement that will handle any of the values that contain ">" or "<", so I am using the following to filter those out, and then convert it to an int value, to determine what the indicator value should be. Here is the line of the script that is erring out"
case when (RESULT not like '%<%') or (RESULT not like '%>%') then CASE WHEN (CONVERT(int, RESULT) between 0 and 500) THEN '2' ELSE '0'
The message I am getting is: Conversion failed when converting the varchar value '<1' to data type int.
I thought a "not like" statement would not include those values for converting to an int, but that does not seem to be working correctly. I did also try moving the not to show as "not RESULT like", and that did not change the message.
How I can filter out non-numeric values before converting the rest of the varchar field (RESULT) to int, so that it is only converting actual numbers?
I'm trying to convert a column in my source table of datatype varchar(6) to a column of datatype int in my destination. I tried using the Derived Column/Data Conversion transformations but none of them worked. So, I tried using the following C# (credits to the original poster) and getting an error during compilation.
Note: "MyCol" is the Input Column I've specified in the Script Component and "CleanCol" is the Output column I've specified as datatype [DT_I4].
public override void Input0_ProcessInputRow(Input0Buffer Row) { int colOut = 0; if (!Int32.TryParse(Row.MyCol, out colOut)) { Row.CleanCol_IsNull = true; } else { Row.CleanCol = colOut; } }
The best overloaded method match for 'int.TryParse(string, out int)' has some invalid arguments
The other expression I've tried was:
ISNULL(MyCol) ? (dt_i4)"" : (dt_i4)MyCol
From the above code, you might have understood that the source field has some blank records as well in the MyCol field.
What is the best possible way to do the conversion from a String to Int or fixing the error from the above.
I am creating a view which involved concatenation of 2 int columns.
The data in the columns look like
Column 1 Column 2 1234 1 12345 11
I am trying to get the following output
001234001 012345011
So the first column should have zeros padded to the front to make 6 numbers, the second column should be 3 numbers long with zeros in front. So when added together it is 9 numbers long.
I am trying to setup an indicator value for an SSRS report to show green and red values on a report, based on the NRESULT value. The problem I am facing is that I have several different CASE statements that have the same logic, and they are processing just fine. NRESULT is a decimal field, so no conversion should be necessary. I do not know why I am getting the "Arithmetic overflow error converting varchar to data type numeric." error message.
Below is the CASE statement where the error is occurring. It is in the part of the ELSE CASE. The first CASE works just fine when the ELSE CASE is commented out. If I also change the ELSE CASE statement to say "else case when LEFT(NRESULT,1) = '-' then '0'", then it processes fine, too, so it has to be something I am missing something in the check on negative values. I do need the two checks, one for positive and one for negative values, to take place.
case when LEFT(NRESULT,1) <> '-' then --This portion, for checking positive values, of the CASE statement works fine. CASE WHEN LEFT(ROUND(NRESULT,2),4) between 0.00 and 0.49 THEN '2' --Green ELSE CASE WHEN LEFT(ROUND(NRESULT,2),4) > 0.49 THEN '0' --Red ELSE '3' --White END END else case when LEFT(NRESULT,1) = '-' then --This portion, for checking negative values, of the CASE statement is producing the conversion error message.
[code]....
I checked the NRESULT field, and there are not any NULL values in there, either.
I have a numeric data field called Price and this has a value of 0.000 in the db. when i create a package to extract this data to a flat file, the value is displayed as .000 what should i do to make it appear as 0.000 in the flat file.
I tried using a derived column expression where i check if the db value is 0.000 and display it as a string "0.000". this works fine if the OLEDB source is a sql command but fails if the OLEDB source is a sql command from variable.
I'm designing a database that will not be that large (I would be surprised if it ever surpassed 50,000 rows across all tables), but will be accessed quite often, so I am doing my best to optimize its structure, such as doing 3NF, selecting appropriate data types, etc.
I have a few columns that will contain numeric data (such as an invoice number (from an external source) or location ID). However, one of my classes in college was about database design, and we were taught that if you won't be doing mathmatic computation on a field (such as the invoice or location fields I mentioned earlier), then you should use a string literal type (char, varchar, etc.)
Unfortunatly, the professor did not explain much as to why this should be done. From the standpoint of semantic analysis, these types of fields are probably more labels than they are numbers. However, I don't find that very convincing (or even helpful).
In short, my question is that given a column holding numeric data that isn't worked on in a mathematical sense, is it really better to mark it as a string literal than a number? Any articles or studies I can read relating to this?
I would think that comparisons would be faster with int, as well as data storage (though, as mentioned, that's not as big of a concern). Sadly, Google doesn't have many helpful resources. (Lots of stuff on char vs varchar, though.)
I read the topic from JROdden and this case is similiar but...
I got several varchar fields with values like 1.2 1.3 ... these I can covert with select CONVERT(dec(5,2), fieldname) as fieldname
In fact I also solved undefined- and NULL-values with. CONVERT(decimal(12, 2), CASE WHEN GESCHKOSTMAX IS NULL OR GESCHKOSTMAX < '0' THEN '0' ELSE GESCHKOSTMAX END) as GESCHKOSTMAX,
But now there are values like 1,4 and these ones neither CONVERT nor CAST will handle.
I tried the SELECT DISTINCT KMPAUSCHALE FROM extr_INTFIRMA WHERE (isnumeric(KMPAUSCHALE) = 1)
and get 0,40 0.25 0.30 and so on...
The error is: [Microsoft][ODBC SQL Driver][SQL Server]Error converting datatype varchar to decimal. (or float or numeric (whatever I tried))
I think the easiest way would be to insist on higher data quality but I also would like to solve this interesting challenge.
Thanks for any hints
By the way, I followed rudys link to http://rudy.ca/afdb.html and now I know how I could protect myself !!!!
There must be a voice in my head saying: Try the db-forum, try it and stay happy... ;-)
I have a table that contains a lot of demographic information. The data is usually small (<20 chars) but ocassionally needs to handle large values (250 chars). Right now its set up for varchar(max) and I don't think I want to do this.
How does varchar(max) store info differently from varchar(250)? Either way doesn't it have to hold the container information? So the word "Crackers" have 8 characters to it and information sayings its 8 characters long in both cases. This meaning its taking up same amount of space?
Also my concern will be running queries off of it, does a varchar(max) choke up queries because the fields cannot be properly analyzed? Is varchar(250) any better?
Should I just go with char(250) and watch my db size explode?
Usually the data that is 250 characters contain a lot of blank space that is removed using a SPROC so its not usually 250 characters for long.
I have to develop a package to get some data from a 10g Oracle database and load it to a SQL Server 2005 database.
In my design I used Oracle Provider for OledDB as my source provider following Microsoft recommendations found here : http://msdn2.microsoft.com/en-us/library/bb332055.aspx
As I have to use a parametrized query against my Oracle database I create a variable with my query that I override at runtime with a script task to update the parameters values.
One of the return column is of numeric datatype.
To handle this known issue with Oracle sources I edited through the advanced editor my Oledb source component to manually correct the precision.
Everything works fine with one of my package.
So I repeat the whole process while designing an other one with the same purposes.
As for the previous one I first unit test every components and everything works. But when running the full package it raised an error code 0x80004005 Error while validating post executing phase of the component (sorry for the poor translation from french to english ...)
I open my dataflow where the component is and found no warnings or errors. I edited through the advanced editor my Oledb source component and found that there's an error on the precision scale of the numeric return column. The message warn me that the precision must be between 1 and 38. I checked this column and in the "OLE DB Source output / External Columns" the precision is 0 though I previously manually corrected it. I upadted again for a 18 precision as it is for this column in "OLE DB Source output / Output Columns". But it never keeps my changes ......
I delete the component and recreate it to force the metadata to be updated but always the same thing, the precision scale for this column in the "OLE DB Source output / External Columns" never keeps my 18 value.
Hello all I want to make a varchar datatype in sqlserver which does not accept numbers ( only letters will be accepted ) what is your suggetion ( I should mention that I use storedprocedures in my applications) sincerely yours Mohsena
I am using a varchar datatype for PIN number to handle zero at start. Now i want to do mathematical calculation to encrypt the PIN so i need to convert that varchar datatype to int so that zero should not be discarted after conversion. i.e. 0123 and 123 must not be treated as same PIN.
Please kindly give me a way out. I am using RSA encryption.
I have the following form in this adress:(it's framework 1.1 asp.net vb.net)http://admin.artemrede.pt/login.aspx?ReturnUrl=%2fdefault.aspxthe utilizador is: testepalavra passe is: 12345I'm using some text datatypes and some very big varchars the problem is that when you try to add a new record or to edit a existing record, if for example in one of the very big varchars or text, textboxes, several lines of text, It only puts in the database the 2 first words that you write. I used the VS debug and apparently everything looks ok......(if it would I probably hadn't this error....) Dim OurConnection As SqlConnectionOurConnection = New SqlConnection(conn_default)Dim OurCommand As SqlCommandOurCommand = New SqlCommand("Insert Into espectaculo (foto_destaque, thumb, area_prog, nome_espectaculo, coord, nome_comp, duracao, f_etaria, sinopse, iterancia, ficha, bio_interv, bio_comp, link_comp, notas_imprensa) Values (@fotod, @thumb, @areap, @ne, @coord, @nc, @duracao, @fe, @sinopse, @it, @ficha, @bioI, @bioC, @link, @notasp)", OurConnection)If (foto_destaque.Text = "") ThenOurCommand.Parameters.Add("@fotod", SqlDbType.VarChar, 12).Value = " "ElseOurCommand.Parameters.Add("@fotod", SqlDbType.VarChar, 12).Value = foto_destaque.TextEnd IfIf (thumb.Text = "") ThenOurCommand.Parameters.Add("@thumb", SqlDbType.VarChar, 12).Value = " "ElseOurCommand.Parameters.Add("@thumb", SqlDbType.VarChar, 12).Value = thumb.TextEnd IfIf (area_prog.Text = "") ThenOurCommand.Parameters.Add("@areap", SqlDbType.VarChar, 50).Value = " "ElseOurCommand.Parameters.Add("@areap", SqlDbType.VarChar, 50).Value = area_prog.TextEnd IfIf (nome_esp.Text = "") ThenOurCommand.Parameters.Add("@ne", SqlDbType.VarChar, 100).Value = " "ElseOurCommand.Parameters.Add("@ne", SqlDbType.VarChar, 100).Value = nome_esp.TextEnd IfIf (coord.Text = "") ThenOurCommand.Parameters.Add("@coord", SqlDbType.VarChar, 100).Value = " "ElseOurCommand.Parameters.Add("@coord", SqlDbType.VarChar, 100).Value = coord.TextEnd IfIf (nome_comp.Text = "") ThenOurCommand.Parameters.Add("@nc", SqlDbType.VarChar, 50).Value = " "ElseOurCommand.Parameters.Add("@nc", SqlDbType.VarChar, 50).Value = nome_comp.TextEnd IfIf (duracao.Text = "") ThenOurCommand.Parameters.Add("@duracao", SqlDbType.VarChar, 25).Value = " "ElseOurCommand.Parameters.Add("@duracao", SqlDbType.VarChar, 25).Value = duracao.TextEnd IfIf (faixa.Text = "") ThenOurCommand.Parameters.Add("@fe", SqlDbType.VarChar, 50).Value = " "ElseOurCommand.Parameters.Add("@fe", SqlDbType.VarChar, 50).Value = faixa.TextEnd IfIf (sinopse.Text = "") ThenOurCommand.Parameters.Add("@sinopse", SqlDbType.VarChar, 8000).Value = " "ElseOurCommand.Parameters.Add("@sinopse", SqlDbType.Text, 16).Value = sinopse.TextEnd IfIf (itener.Text = "") ThenOurCommand.Parameters.Add("@it", SqlDbType.VarChar, 200).Value = " "ElseOurCommand.Parameters.Add("@it", SqlDbType.VarChar, 200).Value = itener.TextEnd IfIf (ficha.Text = "") ThenOurCommand.Parameters.Add("@ficha", SqlDbType.Text, 16).Value = " "ElseOurCommand.Parameters.Add("@ficha", SqlDbType.Text, 16).Value = ficha.TextEnd IfIf (bio_interv.Text = "") ThenOurCommand.Parameters.Add("@bioI", SqlDbType.Text, 16).Value = " "ElseOurCommand.Parameters.Add("@bioI", SqlDbType.Text, 16).Value = bio_interv.TextEnd IfIf (bio_comp.Text = "") ThenOurCommand.Parameters.Add("@bioC", SqlDbType.Text, 16).Value = " "ElseOurCommand.Parameters.Add("@bioC", SqlDbType.Text, 16).Value = bio_comp.TextEnd IfIf (linkComp.Text = "") Or (linkComp.Text = "http://") ThenOurCommand.Parameters.Add("@link", SqlDbType.VarChar, 100).Value = " "ElseOurCommand.Parameters.Add("@link", SqlDbType.VarChar, 100).Value = linkComp.TextEnd IfIf (notas_press.Text = "") ThenOurCommand.Parameters.Add("@notasp", SqlDbType.VarChar, 5000).Value = " "ElseOurCommand.Parameters.Add("@notasp", SqlDbType.VarChar, 5000).Value = notas_press.TextEnd If OurConnection.Open()OurCommand.ExecuteNonQuery()OurConnection.Close()carrega()'grid1.DataBind()End IfEnd Sub Sub carrega()conn_default = ConfigurationSettings.AppSettings("ArtemredeConnection")Dim OurConnection As SqlConnectionOurConnection = New SqlConnection(conn_default)OurConnection.Open() Dim OurCommand As SqlCommandDim SelectCommand As StringSelectCommand = "select id_espectaculo, area_prog, nome_espectaculo, nome_comp from espectaculo"OurCommand = New SqlCommand(SelectCommand, OurConnection) Dim Select_DataAdapter As New SqlDataAdapter(OurCommand)Dim Select_DataSet As New DataSet'Dim SP_DataTable_Rowcount As IntegerSelect_DataAdapter.Fill(Select_DataSet, "Espectaculos")grid1.DataSource = Select_DataSetgrid1.DataBind()OurConnection.Close() End Sub
Hi, I have a talbe with a column type varchar(8000). i am facing problems sometimes as it corsses the limit also have the problems with special characters. so i went through few articles and been advised to use xml datatype. but when i am changing comumn name from varchar (8000) to xml as: alter table tblStudentForm alter column FormDetails xml not null i am getting following error: Msg 9400, Level 16, State 1, Line 1 XML parsing: line 46, character 402, unexpected end of input The statement has been terminated.
When creating tables: If varchar expands according to how long the actual string is in each case, then why not set the varchar max characters very high, rather than be conservative about it? For example, if you think your names will only ever be 30 chars you could set that column to varchar(30).But -- why not go ahead and set the column to varchar(100) anyway to be safe? Or is there some hidden storage cost to using 100 rather than 30 max chars?
I have a table Table1 which has a Col called "Msg" datatype image<binary>. Msg alreay has the plain text or RTF text as a image datatype (binary)If I execute the following query "Select Msg from Table1 where id =3" then this query is returning the following ASCII/Binary data.Msg = "0x7B5C727466315C616E73695C616E7369637067313235325C64656666305C6465666C616E67313033337B5C666F6E7474626C7B5C66305C6673776973735C66707271325C66636861727365743020417269616C3B7D7B5C66315C6673776973735C66707271325C666368617273657430204D6963726F736F667420"Can any body tell me how can I convert the above binary data to plain text from my query?Thanks for any reply.
We have few stored procedures that use nvarchar datatype, this was not issue on SQL server 7.0 but in 2000 becomes a big issue. For example query that runs for 3 minutes in SQL server 2000 by replacing NVARCHAR to VARCHAR the same query runs for 2 seconds. The biggest challenge that I have deals with tables and user-defined datatypes of NVARCHAR that has been bounded to the table. How can I alter those without data corruption?
Need to fetch the date from parent table to chile table. This is the script ....
case When @AccountingDate IS NULL THEN NULL ELSE CONVERT (varchar,@AccountingDate , 101) END, Case When @InventoryDate IS NULL THEN NULL ELSE CONVERT (varchar,@InventoryDate,101) END, Case When @StatusDate IS NULL THEN NULL ELSE CONVERT (varchar,@StatusDate,101) END, Case When @LastInstallmentDate IS NULL THEN NULL ELSE CONVERT (varchar,@LastInstallmentDate,101) END, Case When @RetailFirstPayDate IS NULL THEN NULL ELSE CONVERT (varchar,@RetailFirstPayDate,101) END , Case When @LeaseFirstPayDate IS NULL THEN NULL ELSE CONVERT (varchar,@LeaseFirstPayDate,101) END , Case When @DayToFirstPayment IS NULL THEN NULL ELSE CONVERT (varchar,@DayToFirstPayment,101) END , Case When @EntryDate IS NULL THEN NULL ELSE CONVERT (varchar,@EntryDate,101) END , Case When @DealBookDate IS NULL THEN NULL ELSE CONVERT (varchar,@DealBookDate,101) END , Case When @RealBookDate IS NULL THEN NULL ELSE CONVERT (varchar,@RealBookDate,101) END
Session("matricN") = Trim(TextBox1.Text) Dim txtValue As String txtValue = Session("matricN") da = New SqlDataAdapter("select MatricNumber,Name, Roles from Register where MatricNumber = " & txtValue, addRoleConn1)
MatricNumber is in varchar(50) datatype,, the errror says there is a syntax near "="
I would like to change the datatype on a particular column from varchar to bigint across 100's of tables within a database.
I have the command ready which is:
ALTER TABLE tablename ALTER COLUMN columnname BIGINT
The problem happening is that it seems there are constraints across all the columns in every tables.
The error message is:
Server: Msg 5074, Level 16, State 1, Line 1 The object 'DF__tablename__columnname__0ABD916C' is dependent on column 'columnname'. Server: Msg 4922, Level 16, State 1, Line 1 ALTER TABLE ALTER COLUMN columnname failed because one or more objects access this column.
I understand that if I delete this constraint, then it will let me modify the datatype of the column, but since there are tons of them and they are randomly named, how do I achive changing the datatype across multiple tables in bulk.
Why can varchar datatype variable only 4000 byte? For example: in a storedprocedure declare @aa varchar(8000) ...... while select @aa=@aa+@otherinfo end when the length is more than 4000 ,the data in the behind will be lost
I have a field in a table that stores date of birth. The field's datatype is char(6) and looks like this: 091703 (mmddyy). I want to convert this value to a datetime datatype.
What is the syntax to convert char(6) to datetime?