Cannot Map Tinyint To A SSIS Data Type In Resultset

Dec 15, 2005

If I have an executesql task that returns a result set, if the result set contains a tinyint, I can't find what SSIS data type to declare the variable as. They all cause errors.

View 10 Replies


ADVERTISEMENT

ResultSet Can Not Re-read Row Data For BLOB Type In SqlServer 2000

Jul 11, 2005

I am using SqlServer 2000 and Jdbc connectivity in my application on windows.So, when i execute a query on Sqlserver database as :

Select * from DBO.RS_TABLELOB where Rep_sync_id > 15 and Rep_server_name != 'replicator' order by Rep_sync_id;

This problem is only with the BLOB data types in table RS_TABLELOB.

Then i got an error as:

[Microsoft][SQLServer 2000 Driver for JDBC]ResultSet can not re-read row data for column

1.'.'.at com.microsoft.jdbc.base.BaseExceptions.createExcep tion(Unknown Source)at

com.microsoft.jdbc.base.BaseExceptions.getExceptio n(Unknown Source)at

com.microsoft.jdbc.base.BaseResultSet.validateColu mnIndex(Unknown Source)at

com.microsoft.jdbc.base.BaseResultSet.getObject(Un known Source)at

com.microsoft.jdbc.base.BaseResultSet.getObject(Un known Source)


Please help me out, if you have any idea!!!

Thanks in advance
John Berry

View 1 Replies View Related

COnverting Numeric Data Type (Oracle) To Date Data Type Using SSIS

Mar 7, 2007

We have some columns in a table where the date is stored as 19980101 (YYYYMMDD). The data type for this column is NUMBER(8) in Oracle.

I need to copy rows from Oracle to SQL Server using SSIS. I used the Data Conversion transformation editor to change it to DT_DATE, but the rows are not being inserted to the destination.

On Error, If I fail the component, then the error is :

There was an error with input column "ORDER_DATE_CONV" (1191) on input "OLE DB Destination Input" (29). The column status returned was: "Conversion failed because the data value overflowed the specified type.".

Regards

RH

View 3 Replies View Related

Variable Data Type In SSIS

Aug 31, 2007

how to pass the numeric(12,0) data type to a variable in SSIS? what kind of variable data type should I choose?
I am trying to assign object_key column ( numeric(12,0)) to a variable in SSIS

If i select int32 , it keep giving me an error:
Error: 0xC001F009 at Row by Row process: The type of the value being assigned to variable "User::Object_Key" differs from the current variable type. Variables may not change type during execution. Variable types are strict, except for variables of type Object.

View 3 Replies View Related

Convert Data Type In SSIS

Oct 1, 2007

Hi, all my friends,

This is another rookie one.

Is there a way in SSIS dev environment that will let you convert/cast data type at desing time?

Under data flow mappings, there are so many things you can do, but why I did not find any easy way to convert?

I got this validation warning about not supportng converting type DT_STR to DT_I4, or something related.

Am I missing something obvious?

Thanks!

View 3 Replies View Related

Data Type Mismatch -- SSIS

Mar 5, 2007

Hi All,
I am moving some numerical data from SQL server to excel. After the data is moved, i am getting green flag in excel cell to which the data is moved. I have configured the excel column to accept only numbers, but still i am getting green flag in excel cells. When i click the cell i am getting this message "The number in the cell is formatted as text or preceded by a apostrophe"

Can anyone tell me how can i over come the issue.

Thanks
Anwar











View 4 Replies View Related

Check Numeric Data Type In SSIS

Sep 3, 2007

Dear All,

the situation is that i have a column data comes from flat file and all i want to do is to check that the incoming column is numeric(12,3) and if the incoming data exceed that size "12,3" exception or redirect the row is happened.



the problem that i try to apply that with the data conversion or Derived column component but it in case of the scale of the incoming data exceed 3 the component trim until 3 scale.



i also try to perform it with the flat file data source component but i face a problem that if the data in the column is empty then flat file data source component read the numeric column as Zero



i hope someone help me coz i need to handle it soon.


best wishes
Maylo

View 5 Replies View Related

Simple Vb / Ssis Data Type Questions

Mar 27, 2007

I have a some raw data in a string that looks like



'1989'



I need that to become numeric 19.89



if I define a type double for rawAmount



and do this:



rawAmount = CInt(iRest.Substring(41, 4))

Row.amount2 = rawAmount / 100



where row.amount2 is a type double precision float from my script component task output, I get:



19.899999999999999



what output should i use in this data flow component to get 19.89.



thanks.





View 3 Replies View Related

SSIS Package, How To Transform Data Type Fields.

Oct 12, 2006

Hello,

I have an OLE DB Source and i want to transform the data type fields of the table before i export the table in an OLE DB Destination.
Is there a way to transform numeric value to float, and numeric to nvchar?

Thank you in advance.

View 5 Replies View Related

Convert Data Type In SSIS Design Time

Oct 2, 2007

Hi, all experts,


Is there a way in SSIS dev environment that will let you convert/cast data type at desing time?


Under data flow mappings, there are so many things you can do, but why I did not find any easy way to convert?


I got this validation warning about not supportng converting type DT_STR to DT_I4, or something like that on many occassions..

I am using OLEDB Source as source and SQL Server Destination as destination.

Am I missing something obvious?


Thanks!

View 6 Replies View Related

Data Type In Oracle Is Not Translating In SSIS Datatype

Sep 25, 2006

My OLDB data source in the Lookup Transformation is not converting

When I try to join the colunms it claims the data types do not match the only differnece is the percision.??


ORACLE
select CAST(group_id AS NUMBER(18)) group_id from blah blah table
SSIS data type = [DT_NUMERIC], Percision = 38

SQL Sever data source
SELECT
CAST(PRINCIPAL_ID as numeric) GROUP_ID,
SSIS data type = [DT_NUMERIC], Percision = 18

View 1 Replies View Related

DTS Migration To SSIS - Oracle Unsupport Data Type

Mar 18, 2008



OK I migrated a DTS package from MS SQL 2000 to MS SQL 2005 64-bit SSIS. OK so I fixed a problem with a Double Global Variable... Now I am stuck at a connection to Oracle and it returning data... Here is the error message:

[Execute SQL Task] Error: An error occurred while assigning a value to variable "Remedy_Count": "Unsupported data type on result set binding 0.".

My SQL Statement is this:

SELECT COUNT(*) AS Expr1
FROM DB.MYTABLE

When I run it from the Query Builder it returned this:

EXPR1 = 2983

Here are some details from the General Page on the Execute SQL Task

ResultSet - Single row
ConnectionType - OLE DB
Connection - Oracle Provider for OLE DB
SQLSourceType - Direct input
BypassPrepare - True

In the Result Set I have The following:

Result Name - Variable Name
0 - Remedy_Count

So... what can I do to fix this. I have the Remedy_Count set as a:

EvaluateAsExpression - False
Value - 2414
ValueType - Double

I have tried setting the ValueType to Object and other things... Same error... I read some where about how SSIS has issues when Oracle returns a Numeric type data. Can someone help me with this? Anything you all can tell me would be great.

View 4 Replies View Related

Consuming WCF Service With Complex Data Type In SSIS

Oct 9, 2007



Hi,

Need a guidance on consuming the WCF service with complex type in the SSIS package.
I have a WCF service with complex type inside the complex type (Nested complex type) in the web method as an argument. When I try to use this WCF service in the SSIS web service task, I get an error "The web method has unsupported arguments".

I am able to consume the WCF service with the web method having Complex type and simple/prmitive type in side that as argument.

For example:

The web method in WCF service which accepts the argument as comlex type say "Employee" whose structure is:

Employee
{
FName String;
LName String;
Age int
}

It is possible to consume this WCF service and pass the arguments.

But when the Employee complex type is changed to have one more complex type in side it it give the above mentioned error. The Employee type is modified as:

Employee
{
FName String;
LName String;
Age String
Type EmployeeType;
}


EmployeeType
{
type string;
}

Now I get the error Web Method has unsupported arguments.

Can this be done in SSIS?

Virendra

View 3 Replies View Related

Reporting Services :: SSRS Report Does Not Display Resultset Through Dataset Returns Resultset

Oct 10, 2012

I am creating a simple SSRS table report through Report Builder. My dataset is looking for the stored procedure . When I execute the Stored procedure through SSMS I get resutset for certain parameters. I execute the dataset  (Store procedure) through query designer in dataset properties and I get results back. But when I try to run the report and see the preview, I do not get any results displayed. I been looking on the same issue form last 3-4 days and have not found any clue.

Following is the stored procedure I am using. Also I am passing multivalued parameter through report as well, and I am using spilt function to seperate the libraryid I am reading from parameter values. This works fine. I have similar kind of four other reports and with different stored procedure which exactly follow the same method , like multivalue parameters and other criteria are also very similar. All other reports works just fine.. This perticular report has issue for displying results, following is the stored procedure I am using 

SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

[code]....

View 4 Replies View Related

Is Ssis The Only Technology That Can Read/write Raw Data Type Files?

Sep 21, 2007

I'm contemplating a sql server archive strategy that rolls really old data off any sort of dbms and onto low cost media like dvds in a non relational archive format. I dont want to ever worry about these archives spanning different versions of sql when i go to retrieve a range of data that happens to span sql versions (eg one disc was sourced from 2005 another by 2008 but my report needs a union of both).

So I'm thinking about neutral/efficient formats for these archives and a live homegrown catalog that can determine exactly what disc(s) need to be mounted based on passed from and to date parameters...all so that the data that might span discs (and versions and maybe even schemas) can be merged and loaded into my sql version d'jour's "throw away" archive database for a one time report or other unplanned activity.

I remember raw data types being very convenient as an ETL format for our customers who have ssis, but wouldn't want our sqlexpress customers to be left without the archiving capability. Do the "things" that read and write raw data files really originate in some special T-SQL command that all sql editions can use, or is it strictly an ssis thing?

View 4 Replies View Related

SSIS And SQL Server Destination And Invalid Data For Type Numeric.

Oct 11, 2007

We have an SSIS package that reads in a tab delimited file and throughs the data into a SQL Server 2005 table. The package worked fine on the test files but when we recieved the production files we are getting the error message:

Invalid data for type "numeric".


Needless to say this is not very discriptive. I ran a trace on the DB durning the call and its doing a bulk insert

BULK INSERT [dbo].[FNIAllAppData]
FROM 'GlobalDTSQLIMPORT 00000000000015b800000000009fbd88'
WITH (DATAFILETYPE = 'DTS_Buffers', CODEPAGE = 'RAW', CHECK_CONSTRAINTS, TABLOCK)


When I changed the Data Flow Destination off to OLE DB Destination the error does not occure and all records are loaded successfully.

Any suggestions or help would be appreciated. Thanks.

View 3 Replies View Related

Integration Services :: Data Type Checks In SSIS Package

Oct 13, 2015

I have to perform several data checks before loading data into target table. For example I am having 1 flat file with below column

Id Name Age
Int Varchar(100)  Int

My requirement is to create  package, checks will be performed on each record, column of the files. Any records which failed the checks considered as error records and will be written to the exception table.

View 4 Replies View Related

SSIS Flat File Loading - Data Type Conversion

Apr 24, 2007

It seems I can do the type conversion in two place:

1. The advanced editor for flat file source => Input and output roperties. And I can set the output columns data type properties there.

2. Using a Data conversion box in Data flow transformation.

Any difference between these two? Which one should be used?

View 1 Replies View Related

Integration Services :: SSIS Data Type From Excel File

Jun 9, 2015

I have excel column with numeric and special character values , when I take that into SQL table using SSIS, the special character values enter as null value.  the example column values are given bellow

1
2
2/1 
1/2
1/2 means 1 or 2 ,

how can I read this values exactly into SQL table?

View 13 Replies View Related

Why Cant I Set The Precision For Decimal Data Type In SSIS Flat File Source?

Mar 2, 2007

I have a CSV Flat File Source with a Decimal column - but DataPrecision property is grayed out - why?

View 1 Replies View Related

SSIS Custom Data Flow Component - Variable Type Converter

Jun 27, 2007

Hi all,



I am creating a customer data flow component for SSIS for use in a package. I've got some custom properties that I am exposing using the supplied advanced editor (no custom property editor here).



Some of my properties are enumerated types, and I have deciphered how to get those properties to show as dropdown lists of their respective enumerations. (For those of you who may be looking as hard as I did as to how to accomplish this, see the end of this post.)



I also have a few properties which request SSIS package variable names - such as an file name variable. However, I can't figure out how to tell the advanced editor that the property is looking for an SSIS variable, so that it can show a dropdown list of package variables, much like virtually any other Microsoft supplied Data Flow component can.



Is there a Type Converter I could specify for those custom properties? Is there another way to instruct SSIS that my custom property is expecting a variable? Or do I need to code a custom UI for editing my Data Flow Task?



To create a dropdown list of values for a custom property that represents an enum, do the following:

1. Create your enum definition, such as "public enum ThisIsMyEnum { one, two }"

2. Create a new class that inherits from TypeConverter, such as "public class MyEnumConverter : TypeConverter"

3. Override "CanConvertFrom", and return true if "sourceType == typeof(string)"

4. Override "CanConvertTo", and return true if "destinationType == typeof(string)"

5. Override "ConvertFrom", and return the enum value (such as "one" or "two" in my example) that corresponds to the string passed in the parameter "value"

6. Override "ConvertTo", and return a string that corresponds to the enum value passed in the parameter "value"

7. Override "GetStandardValuesSupported" and return true

8. Override "GetStandarValuesExclusive" and return true to indicate that ONLY the enum values should be accepted

9. Override "GetStandardValues", and return a new StandardValuesCollection constructed with Enum.GetValues() of your enum, such as "return new StandardValuesCollection(Enum.GetValues(typeof(ThisIsMyEnum)));"

10. Just above your "public enum" declaration, add a "TypeConverter" attribute to link your type converter to your enum, such as "[TypeConverter(typeof(MyEnumConverter))]"

11. In "ProvideComponentProperties", after you've created your custom property like this: "IDTSCustomProperty90 propEnum = ComponentMetaData.CustomPropertyCollection.New()", add another line to specify the TypeConverter property of the property to the full assembly name of your type converter, like so: "propEnum.TypeConverter = typeof(MyEnumConverter).AssemblyQualifiedName;"

View 11 Replies View Related

Execute SQL Task (SSIS 2005) SP2 And Resultset To A Parameter

Oct 8, 2007



Hello! I would like to write a value from a column to a parameter in SSIS with the Execute SQL task. The problem is that I will never get a value for the parameter.



You can recreate the problem with the AdventureWorksDW sample database.



1. Drop an execute SQL task in the control flow

2. Set the connection to the AdventureWorksDw database

3. Write this in the SQL Statement box Select Max(FullDateAlterNateKey) as LastDate

From DimTime
4. Set the resultset to single Row
5. Under result set assign LastDate as the Result Name and create a parameter with a default date.
6. Execute the task, that will finish succesfully but the value of the parameter in 5 have not changed.

I have tried to change the scope to both the package level and the task level without any success. The value of the variable is still the default value. I have also tried a string variable without sucess.

Any ideas?

Kind Regards
Thomas Ivarsson

View 5 Replies View Related

Index Creation Causes Error The Conversion Of A Char Data Type To A Datetime Data Type Resulted...

Jul 23, 2005

Hi all,I have a table called PTRANS with few columns (see create script below).I have created a view on top that this table VwTransaction (See below)I can now run this query without a problem:select * from dbo.VwTransactionwhereAssetNumber = '101001' andTransactionDate <= '7/1/2003'But when I create an index on the PTRANS table using the command below:CREATE INDEX IDX_PTRANS_CHL# ON PTRANS(CHL#)The same query that ran fine before, fails with the error:Server: Msg 242, Level 16, State 3, Line 1The conversion of a char data type to a datetime data type resulted inan out-of-range datetime value.I can run the same query by commeting out the AssetNumber clause and itworks fine. I can also run the query commenting out the TransactionDatecolumn and it works fine. But when I have both the conditions in theWHERE clause, it gives me this error. Dropping the index solves theproblem.Can anyone tell me why an index would cause a query to fail?Thanks a lot in advance,AmirCREATE TABLE [PTRANS] ([CHL#] [varchar] (100) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,[CHCENT] [numeric](2, 0) NOT NULL ,[CHYYMM] [numeric](4, 0) NOT NULL ,[CHDAY] [numeric](2, 0) NOT NULL ,[CHTC] [char] (2) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL) ON [PRIMARY]GOCREATE VIEW dbo.vwTransactionsASSELECT CONVERT(datetime, dbo.udf_AddDashes(REPLICATE('0', 2 -LEN(CHCENT)) + CONVERT(varchar, CHCENT) + REPLICATE('0', 4 -LEN(CHYYMM))+ CONVERT(varchar, CHYYMM) + REPLICATE('0', 2 -LEN(CHDAY)) + CONVERT(varchar, CHDAY)), 20) AS TransactionDate,CHL# AS AssetNumber,CHTC AS TransactionCodeFROM dbo.PTRANSWHERE (CHCENT <> 0) AND (CHTC <> 'RA')*** Sent via Developersdex http://www.developersdex.com ***Don't just participate in USENET...get rewarded for it!

View 1 Replies View Related

System.Data.SqlClient.SqlException: The Conversion Of A Char Data Type To A Datetime Data Type Resulted In An Out-of-range Datetime Value.

Dec 14, 2005

After testing out the application i write on the local pc. I deploy it to the webserver to test it out. I get this error.

System.Data.SqlClient.SqlException: The conversion of a char data type to a
datetime data type resulted in an out-of-range datetime value.

Notes: all pages that have this error either has a repeater or datagrid which load data when page loading.

At first I thought the problem is with the date, but then I can see
that some other pages that has datagrid ( that has a date field) work
just fine.

anyone having this problem before?? hopefully you guys can help.

Thanks,

View 4 Replies View Related

How To Convert String Data Type To DateTime In Derived Column Control In SSIS Package

Jun 26, 2006

Hi ,

I am Using Derived column between Source and Destination Control. the Source input column PriceTime is String Data type. but in the Destination is should be a DATE TIME column. How to Convert this string to DateTime in the Derivied Column Control.

I already tried to in the Derived column control

PRICEDATETIME <add as new column> ((DT_DBTIMESTAMP)priceDateTime) database timestamp [DT_DBTIMESTAMP]



But still throwing Error showing type case probelm



Pls help me on this



Thanks & Regards

Jeyakumar.M






View 23 Replies View Related

Integration Services :: How To Change SSIS Packages Deployed To MSDB - Image Data Type

Jun 22, 2014

Is there a way to change an image data type? I want to make a change to some deployed SQL 2008 SSIS deployed packages. I have a TSQL SELECT that searches the packages for a string. But I would like to be able to change a string. I have googled it but cannot find anything.

View 5 Replies View Related

Converting A Data Type Double To A Type Float Using A Data Adapter &&amp; SSCE 3.5

Feb 13, 2008

Hi,

I can populate a dataTable with type double (C#) of say '1055.01' however when I save these to the CE3.5 database using a float(CE3.5) I lose the decimal portion. The 'offending' code is:


this.court0TableAdapter1.Update(this.mycourtsDataSet1.Court0);

this.mycourtsDataSet1.AcceptChanges();

this.court0TableAdapter1.Fill(this.mycourtsDataSet1.Court0);


This did not happen with VS2005/CE3.01.

I have tried changing all references to decimal (or money in CE3.5) without luck.

I'm beginning to think that string may be the way to go!!!!!!!

Can someone shed some light on my problem.

Thanks,

Later:

It's necessary to update the datatable adapter as the 3.01 and 3.5 CE are not compatible.

View 4 Replies View Related

SqlDataReader And Tinyint

Apr 17, 2005

I have an SP that returns a result set that contains a tinyint.  My problem is that, when I try and access this value using GetInt16 (or 32), I get an error saying that "Specified cast is not valid".  TinyInt is 1 byte, or 8 bits.  GetInt16 'Gets the value of the specified column as a 16-bit unsigned integer'.  I am assuming that this is the root cause of my problem.  But, there doesn't seem to be a GetInt8 ?!  Any ideas?
Thanks, Martin

View 1 Replies View Related

Get Data From Last Row Of A Resultset...(SQL 2005)

May 7, 2008

Hi,
Just when I thought I knew SQL...

I have a stored proc that returns several resultsets to an ASP.NET application. One of these resultsets is sorted by date and I need to access the highest date (i.e. the one on the last row) and store it in a local var in the sproc for use in a separate query. How can I do this? Obviously I want the entire resultset to be returned as usual but I also don't want to execute the same query twice.

e.g.
Original sproc is:
===================================
select id from table
...
select adate from anothertable order by adate
...
select somethingelse from yetanothertable
...
===================================
This normally returns 3 resultsets accessible from ASP.NET.


However I want to get the highest "adate" from that middle query and use it later i.e:
===================================
select id from table
...
declare mydate datetime
select adate from anothertable order by adate (<--somewhere here "mydate" is set to the max date)
...
update somewhere set value = 1 where thedate = mydate
...
select somethingelse from yetanothertable
...
===================================

without changing the data returned to asp.net. Easy? I hope so :-)

Thanks for any help!!

View 4 Replies View Related

Tinyint Overflow Error

Jan 16, 2006

I encounter the following error :

Server: Msg 8115, Level 16, State 2, Procedure kssp_UpdateLeague, Line 107
Arithmetic overflow error converting expression to data type tinyint.

When I hit the following code:

SET @A = @B - @C

-------------------------------------------

@A is defined as :
DECLARE @A INT

@B and @C are populated in a fetch :
FETCH NEXT FROM FixtureList INTO @B, @C

and FixtureList is defined as :

DECLARE FixtureList CURSOR FOR
SELECT HomeScore, AwayScore FROM fixtures
WHERE homescore IS NOT NULL AND awayscore IS NOT NULL

The fields HomeScore and AwayScore are defined as Tinyint

@B and @C are typically between 0 and 10. I reckon the problem may be with the precision of the data types but I don't know how to prove this or how to fix. I've tried various combinations of convert and cast at various points in the expression (SET @A = @B - @C) but to no avail.

Interestingly (or not) if I run the following select I get the same error :

SELECT DATE01, HOMESCORE, AWAYSCORE, HOMESCORE - AWAYSCORE FROM fixtures

View 4 Replies View Related

Exporting Data To Excel From T-SQL Resultset

Apr 8, 2007



I have started just using SSIS. I needed to transfer result set from SQL statements like SELECT * FROM Employee to excel spreadsheet. One way of getting this is using import and export wizard from management studio.



As my sql statement is complex joining many tables. I am wondering wheteher there are other best ways to deal such type of transformations.



I am sure this is very simple question but yours feedback will be much appreciated.

View 3 Replies View Related

Validate INT, SMALLINT, TINYINT & DECIMAL

Jan 10, 2008

Hi all,

I found a UDF on the web to validate INT data contained in a VARCHAR field:

http://blog.sqlauthority.com/2007/08/11/sql-server-udf-validate-integer-function/

I modified it to accept NULL values and conform more closely to INT specification. Here is my modified function:


CREATE FUNCTION [dbo].[udfIsValidINT]
(
@Number VARCHAR(100)
)
RETURNS BIT
BEGIN
DECLARE @Ret BIT, @ShiftByOne INT;
IF LEFT(@Number, 1) = '-'
SELECT @Number = SUBSTRING(@Number, 2, LEN(@Number)), @ShiftByOne=1;
SELECT @Number = COALESCE(@Number,'0'), @ShiftByOne = COALESCE(@ShiftByOne,0)
IF (PATINDEX('%[^0-9-]%', @Number) = 0
AND CHARINDEX('-', @Number) <= 1
AND @Number NOT IN ('.', '-', '+', '^')
AND LEN(@Number)>0
AND LEN(@Number)<11
AND @Number NOT LIKE '%-%')
SELECT @Ret = CASE WHEN CONVERT(BIGINT,@Number) - @ShiftByOne <= 2147483647
THEN 1 ELSE 0 END
ELSE
SET @Ret = 0
RETURN @Ret
END
GO
SELECT dbo.udfIsValidINT('2147483648')
SELECT dbo.udfIsValidINT('2147483647')
SELECT dbo.udfIsValidINT('-200')
SELECT dbo.udfIsValidINT('-2147483649')
SELECT dbo.udfIsValidINT('32900')
SELECT dbo.udfIsValidINT('1.79E+308')
GO


I also have a separate function for SMALLINT:

CREATE FUNCTION [dbo].[udfIsValidSMALLINT]
(
@Number VARCHAR(100)
)
RETURNS BIT
BEGIN
DECLARE @Ret BIT, @ShiftByOne INT;
IF LEFT(@Number, 1) = '-'
SELECT @Number = SUBSTRING(@Number, 2, LEN(@Number)), @ShiftByOne=1;
SELECT @Number = COALESCE(@Number,'0'), @ShiftByOne = COALESCE(@ShiftByOne,0)
IF (PATINDEX('%[^0-9-]%', @Number) = 0
AND CHARINDEX('-', @Number) <= 1
AND @Number NOT IN ('.', '-', '+', '^')
AND LEN(@Number)>0
AND LEN(@Number)<6
AND @Number NOT LIKE '%-%')
SELECT @Ret = CASE WHEN CONVERT(INT,@Number) - @ShiftByOne <= 32677 THEN 1 ELSE 0 END
ELSE
SET @Ret = 0
RETURN @Ret
END
GO
SELECT dbo.udfIsValidSMALLINT('589')
SELECT dbo.udfIsValidSMALLINT('-200')
SELECT dbo.udfIsValidSMALLINT('-32900')
SELECT dbo.udfIsValidSMALLINT('32900')
SELECT dbo.udfIsValidSMALLINT('1.79E+308')


and one for TINYINT:


CREATE FUNCTION [dbo].[udfIsValidTINYINT]
(
@Number VARCHAR(100)
)
RETURNS BIT
BEGIN
DECLARE @Ret BIT, @L TINYINT;
SET @L = LEN(@Number);
SET @Number = COALESCE(@Number,'0');
IF (PATINDEX('%[^0-9]%', @Number) = 0
AND @L>0
AND @L<4)
SELECT @Ret = CASE WHEN CONVERT(SMALLINT,@Number) < 256 THEN 1 ELSE 0 END
ELSE
SET @Ret = 0
RETURN @Ret
END
GO
SELECT dbo.udfIsValidTINYINT('256')
SELECT dbo.udfIsValidTINYINT('-1')
SELECT dbo.udfIsValidTINYINT('0')
SELECT dbo.udfIsValidTINYINT('255')
SELECT dbo.udfIsValidTINYINT('1.79E+308')


And, finally, a separate function for DECIMAL validation:

CREATE FUNCTION [dbo].[udfIsValidDECIMAL]
(
@Number VARCHAR(100),
@Scale TINYINT,
@Precision TINYINT
)
RETURNS BIT
BEGIN
DECLARE @Ret BIT, @L TINYINT, @DSI TINYINT;
SET @Number = COALESCE(@Number,'0');
IF LEFT(@Number, 1) = '-'
SELECT@Number = SUBSTRING(@Number, 2, LEN(@Number));
SET @L = LEN(@Number);
SET @DSI = @L - LEN(REPLACE(@Number,'.',''))
IF(
PATINDEX('%[^0-9.]%', @Number) = 0
ANDCHARINDEX('-', @Number) = 0
AND@DSI <= 1
AND@L>0
AND@L<=@Scale+@DSI+ CASE @DSI WHEN 1 THEN @L-CHARINDEX('.', @Number) ELSE 0 END
AND @Scale - @Precision >= CASE @DSI WHEN 1 THEN CHARINDEX('.', @Number) - 1 ELSE @L END
)
SELECT @Ret = 1
ELSE
SET @Ret = 0
RETURN @Ret
END
GO
SELECT dbo.udfIsValidDECIMAL('256',2,0)
SELECT dbo.udfIsValidDECIMAL('-1',1,0)
SELECT dbo.udfIsValidDECIMAL('10.123456789123456789',18,17)
SELECT dbo.udfIsValidDECIMAL('10.123456789123456789',18,16)
SELECT dbo.udfIsValidDECIMAL('-255.0000000000000001',3,0)
SELECT dbo.udfIsValidDECIMAL('1.79E+308',9,2)


Node that the DECIMAL validation function specifically tests whether the input number can legally convert to a given decimal scale and precision. Converting a value of 0.234234 over to DECIMAL(1,0) will work, but SQL will truncate the actual decimals to fit it in that space. However, it will throw an error if you have too many whole digits.

On the whole, I was rather rushed to get these created, so there may be some errors I didn't notice. I'm interested in any improvements you guys can make to improve performance or make them cleaner.

Thanks for looking!

- Shane

View 2 Replies View Related

The Conversion Of A Char Data Type To A Datetime Data Type!!

May 13, 2008

hello all .. I have a form that includes two textboxes (Date and Version) .. When I try to insert the record I get the following error message .. seems that something wrong with my coversion (Data type)"The conversion of a char data type to a datetime data type resulted in an out-of-range datetime value.The statement has been terminated."
 
in my SQL database I have the date feild as datetime and the version as nvarchar(max)
this is the code in the vb page .. Can you please tell me how to solve this problem?Imports System.Data.SqlClient
Imports system.web.configuration

Partial Class Admin_emag_insert
Inherits System.Web.UI.Page

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Record_DateTextBox.Text = DateTime.Now

End Sub

Protected Sub clearButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles clearButton.Click
Me.VersionTextBox.Text = ""
End Sub

Protected Sub addButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles addButton.Click
Dim objConnection As SqlConnection
Dim objDataCommand As SqlCommand
Dim ConnectionString As String
Dim record_date As Date
Dim version As String
Dim emagSQL As String

'save form values in variables
record_date = Record_DateTextBox.Text
version = VersionTextBox.Text

ConnectionString = WebConfigurationManager.ConnectionStrings("HRDBConnectionString").ConnectionString

'Create and open the connection
objConnection = New SqlConnection(ConnectionString)
objConnection.Open()
emagSQL = "Insert into E_Magazine (Record_Date, Version ) " & _
"values('" & record_date & "','" & version & "')"

'Create and execute the command
objDataCommand = New SqlCommand(emagSQL, objConnection)
objDataCommand.ExecuteNonQuery()
objConnection.Close()

AddMessage.Text = "A new emagazine was added successfully"

Me.VersionTextBox.Text = ""

End Sub
End Class
 

View 10 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved