Showing posts with label int. Show all posts
Showing posts with label int. Show all posts

Friday, February 24, 2012

Data types - using integer as numerator in a percentage calculation

I know I'm probably going to get rapped in the mouth for my stupidity but,
in SQL Server 2000
Price is money(8), Qty Is int(4)
Discount Is int(4) - the program that it feeds into doesn't accept fractions
of a discount
The statement:
SELECT Items.Price, Items.discount,
(Items.Price - (Items.Price * (Items.discount / 100))) *
Items.Qty AS Extension
FROM Items
Returns
29.9900 10 29.98000
Heck, even
SELECT (10/100)
reurns zero
SELECT CAST((10/100) AS Real)
returns 0.0
What am I doing wrong?
JulianOh, please don't tell me that all I had to do was put a ".0" at the end of
the "100" ...
julian
"stjulian" <anonymous@.discussions.microsoft.com> wrote in message
news:ef%23EbupJGHA.1424@.TK2MSFTNGP12.phx.gbl...
>I know I'm probably going to get rapped in the mouth for my stupidity but,
> in SQL Server 2000
> Price is money(8), Qty Is int(4)
> Discount Is int(4) - the program that it feeds into doesn't accept
> fractions
> of a discount
> The statement:
> SELECT Items.Price, Items.discount,
> (Items.Price - (Items.Price * (Items.discount / 100))) *
> Items.Qty AS Extension
> FROM Items
> Returns
> 29.9900 10 29.98000
>
>
> Heck, even
> SELECT (10/100)
> reurns zero
>
> SELECT CAST((10/100) AS Real)
> returns 0.0
>
> What am I doing wrong?
> Julian
>
>
>|||Julian, You need to CAST early, either implicitly or explicitly
(Items.Price - (Items.Price * (Items.discount / 100.0)))
Adding the .0 to the end of 100 will cause it to be treated as float. Or
you can CAST you number as DECIMAL(5,2) or whatever works for you.
RLF
"stjulian" <anonymous@.discussions.microsoft.com> wrote in message
news:ef%23EbupJGHA.1424@.TK2MSFTNGP12.phx.gbl...
>I know I'm probably going to get rapped in the mouth for my stupidity but,
> in SQL Server 2000
> Price is money(8), Qty Is int(4)
> Discount Is int(4) - the program that it feeds into doesn't accept
> fractions
> of a discount
> The statement:
> SELECT Items.Price, Items.discount,
> (Items.Price - (Items.Price * (Items.discount / 100))) *
> Items.Qty AS Extension
> FROM Items
> Returns
> 29.9900 10 29.98000
>
>
> Heck, even
> SELECT (10/100)
> reurns zero
>
> SELECT CAST((10/100) AS Real)
> returns 0.0
>
> What am I doing wrong?
> Julian
>
>
>|||Ok then. I won't tell you.
"stjulian" <anonymous@.discussions.microsoft.com> wrote in message
news:%239vjmwpJGHA.1676@.TK2MSFTNGP09.phx.gbl...
> Oh, please don't tell me that all I had to do was put a ".0" at the end of
> the "100" ...
> julian
>
> "stjulian" <anonymous@.discussions.microsoft.com> wrote in message
> news:ef%23EbupJGHA.1424@.TK2MSFTNGP12.phx.gbl...
>|||> SELECT (10/100)
> reurns zero
This is called integer math.
http://www.aspfaq.com/2483|||I'm a dunce.
<8(
julian
"stjulian" <anonymous@.discussions.microsoft.com> wrote in message
news:%239vjmwpJGHA.1676@.TK2MSFTNGP09.phx.gbl...
> Oh, please don't tell me that all I had to do was put a ".0" at the end of
> the "100" ...
> julian
>
> "stjulian" <anonymous@.discussions.microsoft.com> wrote in message
> news:ef%23EbupJGHA.1424@.TK2MSFTNGP12.phx.gbl...
>

Sunday, February 19, 2012

Data type problem

Greetings SSIS friends,

I cast one of my fields from a decimal to an int in my data source (generated from a SQL command). But when I try and map that field to another one of my tables, i get an error saying that I can not cvonvert from decimal to Int32.

Is there any solution which doest require using the derived column or data conversion components?!

Your help would be appreciated.

Can you provide your SQL so that we can look at it? If you are casting to an integer from a decimal in the SQL, SSIS should only see an integer...|||

Hi Phil,

That's what I don't understand.

The SQL is pretty straightforward to be honest.

select
distinct
b.eventid as evt_eventid,
b.meetid as evt_meetid,
cast(h.longname as varchar) as evt_long_name,
cast(h.shortname as varchar) as evt_source_short_name,
b.expstartdate as evt_expstartdate,
b.expstarttime as evt_expstarttime,
b.eventnumber as evt_eventnumber,
b.expertgroup as evt_expertgroup,
b.currentrun as evt_currentrun,
b.enddate as evt_enddate,
b.endtime as evt_endtime,
b.eventstatus as evt_eventstatus,
f.etypeid evt_etypeid,
cast(g.longname as varchar) as evt_type_long_name,
cast(h.longname as varchar) as evt_name,
b.maxplaces as evt_maxplaces,
b.maxpayout as evt_specific_maxpayout,
f.maxpayout as evt_default_type_maxpayout,
b.offdate as evt_offdate,
b.offtime as evt_offtime,
cast(b.callitap as char(1)) as evt_callitap,
cast(isnull(b.maxstake, 0) as int) as evt_maxstake,
b.scoop6leg as evt_scoop6leg,
b.riskoff as evt_riskoff,
b.userofftime as evt_userofftime,
b.delayofftime as evt_delayofftime,
cast(b.suspendliability as int) as evt_suspendliability,
b.termsid as evt_specific_termsid,
i.termsid as evt_default_termsid,
cast(j.longname as varchar) as evt_default_terms,
cast(l.longname as varchar) as specific_evt_terms,
convert(varchar(20), convert(bigint, b.updatetimestamp)) as evt_updatetimestamp
from meetings as a
inner join events as b
on a.meetid = b.meetid
inner join names as c
on a.nameid = c.nameid
inner join EvenType as d
on a.etypeid = d.etypeid
inner join names as e
on d.nameid = e.nameid
inner join EvenType as f
on b.etypeid = f.etypeid
inner join names as g
on f.nameid = g.nameid
inner join names as h
on b.nameid = h.nameid
inner join terms as i
on f.termsid = i.termsid
inner join names as j
on i.nameid = j.nameid
left join terms as k
on b.termsid = k.termsid
left join names as l
on k.nameid = l.nameid
where
convert(varchar(20), convert(bigint, a.updatetimestamp)) > ?
or convert(varchar(20), convert(bigint, b.updatetimestamp)) > ?

order by b.meetid, b.eventid

In SSIS however, it still thinks the column is a decimal.

|||Did you previously have the decimal coming into the source and then later changed the SQL to cast it to an integer?

In the source column mappings, delete the row that corresponds to the column you are working with, and re-map it. Does that help?|||

Hi Phil,

Yes you are right. I unmapped the column and then remaped it and reconfigured my other merge joins and it is now in the data type that I cast it in the SQL code.

Thanks for your help.

Data type int to char

Hi again everyone,
I build a temp table with a data type of int on one column. I then use BCP
to export this table to a TXT file. I use the -c option and also the -t""
(no column delimiter).
The problem I am having is that I am limited to 5 characters for this column
by the company the data is being sent too (archaic I know, I think they are
reading it with Cobol) and the int exports to about 9 characters.
Is there a way to change an int to a char on the fly with INSERT? Something
like CAST?
Beating my brains out, thanks for any suggestions.
George
george collins wrote:
> Hi again everyone,
> I build a temp table with a data type of int on one column. I then
> use BCP to export this table to a TXT file. I use the -c option and
> also the -t"" (no column delimiter).
> The problem I am having is that I am limited to 5 characters for this
> column by the company the data is being sent too (archaic I know, I
> think they are reading it with Cobol) and the int exports to about 9
> characters.
> Is there a way to change an int to a char on the fly with INSERT?
> Something like CAST?
> Beating my brains out, thanks for any suggestions.
> George
You can optionally use a query with BCP. That would give you the
opportunity to convert the INT into a char(5). But you may have problems
if the values in the INT are greater than 99,999 since you'll run into 6
digit numbers.
David Gugick
Imceda Software
www.imceda.com
|||Yeah, I ran in to that kind of issue, what my main problem was the original
character type was a float which would not convert. I changed that to an
int and I am off and running.
Thanks.
"David Gugick" <davidg-nospam@.imceda.com> wrote in message
news:%23enR57ooEHA.3464@.tk2msftngp13.phx.gbl...
> george collins wrote:
> You can optionally use a query with BCP. That would give you the
> opportunity to convert the INT into a char(5). But you may have problems
> if the values in the INT are greater than 99,999 since you'll run into 6
> digit numbers.
> --
> David Gugick
> Imceda Software
> www.imceda.com
>

Data type int to char

Hi again everyone,
I build a temp table with a data type of int on one column. I then use BCP
to export this table to a TXT file. I use the -c option and also the -t""
(no column delimiter).
The problem I am having is that I am limited to 5 characters for this column
by the company the data is being sent too (archaic I know, I think they are
reading it with Cobol) and the int exports to about 9 characters.
Is there a way to change an int to a char on the fly with INSERT? Something
like CAST?
Beating my brains out, thanks for any suggestions.
Georgegeorge collins wrote:
> Hi again everyone,
> I build a temp table with a data type of int on one column. I then
> use BCP to export this table to a TXT file. I use the -c option and
> also the -t"" (no column delimiter).
> The problem I am having is that I am limited to 5 characters for this
> column by the company the data is being sent too (archaic I know, I
> think they are reading it with Cobol) and the int exports to about 9
> characters.
> Is there a way to change an int to a char on the fly with INSERT?
> Something like CAST?
> Beating my brains out, thanks for any suggestions.
> George
You can optionally use a query with BCP. That would give you the
opportunity to convert the INT into a char(5). But you may have problems
if the values in the INT are greater than 99,999 since you'll run into 6
digit numbers.
--
David Gugick
Imceda Software
www.imceda.com|||Yeah, I ran in to that kind of issue, what my main problem was the original
character type was a float which would not convert. I changed that to an
int and I am off and running.
Thanks.
"David Gugick" <davidg-nospam@.imceda.com> wrote in message
news:%23enR57ooEHA.3464@.tk2msftngp13.phx.gbl...
> george collins wrote:
>> Hi again everyone,
>> I build a temp table with a data type of int on one column. I then
>> use BCP to export this table to a TXT file. I use the -c option and
>> also the -t"" (no column delimiter).
>> The problem I am having is that I am limited to 5 characters for this
>> column by the company the data is being sent too (archaic I know, I
>> think they are reading it with Cobol) and the int exports to about 9
>> characters.
>> Is there a way to change an int to a char on the fly with INSERT?
>> Something like CAST?
>> Beating my brains out, thanks for any suggestions.
>> George
> You can optionally use a query with BCP. That would give you the
> opportunity to convert the INT into a char(5). But you may have problems
> if the values in the INT are greater than 99,999 since you'll run into 6
> digit numbers.
> --
> David Gugick
> Imceda Software
> www.imceda.com
>

data Type equivalent in SQL Server

What is the sqlserver equivalent of MS Access INT datatype?Arul,
From the Access docs:
ANSI SQL
data type Microsoft Jet
SQL data type
Synonym Microsoft SQL
Server data type
BIT, BIT VARYING BINARY (See Notes) VARBINARY,
BINARY VARYING
BIT VARYING BINARY, VARBINARY
Not supported BIT (See Notes) BOOLEAN, LOGICAL, LOGICAL1, YESNO BIT
Not supported TINYINT INTEGER1, BYTE TINYINT
Not supported COUNTER (See Notes) AUTOINCREMENT (See Notes)
Not supported MONEY CURRENCY MONEY
DATE, TIME, TIMESTAMP DATETIME DATE, TIME (See Notes) DATETIME
Not supported UNIQUEIDENTIFIER GUID UNIQUEIDENTIFIER
DECIMAL DECIMAL NUMERIC, DEC DECIMAL
REAL REAL SINGLE, FLOAT4, IEEESINGLE REAL
DOUBLE PRECISION, FLOAT FLOAT DOUBLE, FLOAT8, IEEEDOUBLE, NUMBER (See
Notes) FLOAT
SMALLINT SMALLINT SHORT, INTEGER2 SMALLINT
INTEGER INTEGER LONG, INT, INTEGER4 INTEGER
INTERVAL Not supported Not supported
Not supported IMAGE LONGBINARY, GENERAL, OLEOBJECT IMAGE
Not supported TEXT (See Notes) LONGTEXT, LONGCHAR, MEMO, NOTE, NTEXT
(See Notes) TEXT
CHARACTER, CHARACTER VARYING, NATIONAL CHARACTER, NATIONAL CHARACTER
VARYING CHAR (See Notes) TEXT(n), ALPHANUMERIC, CHARACTER, STRING, VARCHAR,
CHARACTER VARYING, NCHAR, NATIONAL CHARACTER, NATIONAL CHAR, NATIONAL
CHARACTER VARYING, NATIONAL CHAR VARYING (See Notes) CHAR, VARCHAR, NCHAR,
NVARCHAR
HTH
Jerry
"Arul" <Arul@.discussions.microsoft.com> wrote in message
news:CD7AAB64-2F05-4C97-B947-B3E47CD460F5@.microsoft.com...
> What is the sqlserver equivalent of MS Access INT datatype?|||We'll that didn't come over well. OK...INT.
HTH
Jerry
"Jerry Spivey" <jspivey@.vestas-awt.com> wrote in message
news:%23f2EB4FyFHA.2228@.TK2MSFTNGP11.phx.gbl...
> Arul,
> From the Access docs:
> ANSI SQL
> data type Microsoft Jet
> SQL data type
> Synonym Microsoft SQL
> Server data type
> BIT, BIT VARYING BINARY (See Notes) VARBINARY,
> BINARY VARYING
> BIT VARYING BINARY, VARBINARY
> Not supported BIT (See Notes) BOOLEAN, LOGICAL, LOGICAL1, YESNO BIT
> Not supported TINYINT INTEGER1, BYTE TINYINT
> Not supported COUNTER (See Notes) AUTOINCREMENT (See Notes)
> Not supported MONEY CURRENCY MONEY
> DATE, TIME, TIMESTAMP DATETIME DATE, TIME (See Notes) DATETIME
> Not supported UNIQUEIDENTIFIER GUID UNIQUEIDENTIFIER
> DECIMAL DECIMAL NUMERIC, DEC DECIMAL
> REAL REAL SINGLE, FLOAT4, IEEESINGLE REAL
> DOUBLE PRECISION, FLOAT FLOAT DOUBLE, FLOAT8, IEEEDOUBLE, NUMBER (See
> Notes) FLOAT
> SMALLINT SMALLINT SHORT, INTEGER2 SMALLINT
> INTEGER INTEGER LONG, INT, INTEGER4 INTEGER
> INTERVAL Not supported Not supported
> Not supported IMAGE LONGBINARY, GENERAL, OLEOBJECT IMAGE
> Not supported TEXT (See Notes) LONGTEXT, LONGCHAR, MEMO, NOTE, NTEXT
> (See Notes) TEXT
> CHARACTER, CHARACTER VARYING, NATIONAL CHARACTER, NATIONAL CHARACTER
> VARYING CHAR (See Notes) TEXT(n), ALPHANUMERIC, CHARACTER, STRING,
> VARCHAR, CHARACTER VARYING, NCHAR, NATIONAL CHARACTER, NATIONAL CHAR,
> NATIONAL CHARACTER VARYING, NATIONAL CHAR VARYING (See Notes) CHAR,
> VARCHAR, NCHAR, NVARCHAR
>
> HTH
> Jerry
> "Arul" <Arul@.discussions.microsoft.com> wrote in message
> news:CD7AAB64-2F05-4C97-B947-B3E47CD460F5@.microsoft.com...
>|||The datatype in sqlserver is varchar for the column I'm working on. I used
cast(column_name as int) when creating a view. I linked this view in access
db. When I join these two objects, its gives me a datatype mismatch error!
"Jerry Spivey" wrote:

> Arul,
> From the Access docs:
> ANSI SQL
> data type Microsoft Jet
> SQL data type
> Synonym Microsoft SQL
> Server data type
> BIT, BIT VARYING BINARY (See Notes) VARBINARY,
> BINARY VARYING
> BIT VARYING BINARY, VARBINARY
> Not supported BIT (See Notes) BOOLEAN, LOGICAL, LOGICAL1, YESNO BIT
> Not supported TINYINT INTEGER1, BYTE TINYINT
> Not supported COUNTER (See Notes) AUTOINCREMENT (See Notes)
> Not supported MONEY CURRENCY MONEY
> DATE, TIME, TIMESTAMP DATETIME DATE, TIME (See Notes) DATETIME
> Not supported UNIQUEIDENTIFIER GUID UNIQUEIDENTIFIER
> DECIMAL DECIMAL NUMERIC, DEC DECIMAL
> REAL REAL SINGLE, FLOAT4, IEEESINGLE REAL
> DOUBLE PRECISION, FLOAT FLOAT DOUBLE, FLOAT8, IEEEDOUBLE, NUMBER (Se
e
> Notes) FLOAT
> SMALLINT SMALLINT SHORT, INTEGER2 SMALLINT
> INTEGER INTEGER LONG, INT, INTEGER4 INTEGER
> INTERVAL Not supported Not supported
> Not supported IMAGE LONGBINARY, GENERAL, OLEOBJECT IMAGE
> Not supported TEXT (See Notes) LONGTEXT, LONGCHAR, MEMO, NOTE, NTEXT
> (See Notes) TEXT
> CHARACTER, CHARACTER VARYING, NATIONAL CHARACTER, NATIONAL CHARACTER
> VARYING CHAR (See Notes) TEXT(n), ALPHANUMERIC, CHARACTER, STRING, VARCHAR
,
> CHARACTER VARYING, NCHAR, NATIONAL CHARACTER, NATIONAL CHAR, NATIONAL
> CHARACTER VARYING, NATIONAL CHAR VARYING (See Notes) CHAR, VARCHAR, NCHAR,
> NVARCHAR
>
> HTH
> Jerry
> "Arul" <Arul@.discussions.microsoft.com> wrote in message
> news:CD7AAB64-2F05-4C97-B947-B3E47CD460F5@.microsoft.com...
>
>|||Check the values. I bet at least one of them is not numeric!
select *
from <table>
where (isnumeric(column) = 0)
ML|||Can you post the syntax of the query you are trying to run?
----
Louis Davidson - http://spaces.msn.com/members/drsql/
SQL Server MVP
"Arguments are to be avoided: they are always vulgar and often convincing."
(Oscar Wilde)
"Arul" <Arul@.discussions.microsoft.com> wrote in message
news:08463266-E902-47E5-A7D2-0E12C6AA3BA7@.microsoft.com...
> The datatype in sqlserver is varchar for the column I'm working on. I
> used
> cast(column_name as int) when creating a view. I linked this view in
> access
> db. When I join these two objects, its gives me a datatype mismatch
> error!
> "Jerry Spivey" wrote:
>|||how are you linking. most probably that is ado vs dao error in access. Chang
e
Controls to use ado by default in access.
Regards
R.D
--Knowledge gets doubled when shared
"Louis Davidson" wrote:

> Can you post the syntax of the query you are trying to run?
> --
> ----
--
> Louis Davidson - http://spaces.msn.com/members/drsql/
> SQL Server MVP
> "Arguments are to be avoided: they are always vulgar and often convincing.
"
> (Oscar Wilde)
> "Arul" <Arul@.discussions.microsoft.com> wrote in message
> news:08463266-E902-47E5-A7D2-0E12C6AA3BA7@.microsoft.com...
>
>

Friday, February 17, 2012

Data Type Conversions

I am trying to convert int to date. first I have converted the int value to string(dt_str), using 'Data Conversion' Transformation, then again I have used another 'Data Conversion' Transformation to convert it into date. but its giving the following error

[Data Conversion 1 [3643]] Error: Data conversion failed while converting column "THEDATE_INTO_STR" (2799) to column "CALENDAR_YEAR1" (3657). The conversion returned status value 2 and status text "The value could not be converted because of a potential loss of data.".


What are the simple ways to convert from one data type to another? If somebody could give some example of the above...............Try using the Derived Column component to do the casting. Its more flexible than Data Conversion component.

-Jamie|||Right, you might need the flexibility of expressions in derived column.
What is the meaning of the integer as a date?|||int as a date meansI have one int type in source, which has data like20051211....
but my target column is of datetime.
Anyways, it done now...

Thanks

Data Type Conversions

I am trying to convert int to date. first I have converted the int value to string(dt_str), using 'Data Conversion' Transformation, then again I have used another 'Data Conversion' Transformation to convert it into date. but its giving the following error

[Data Conversion 1 [3643]] Error: Data conversion failed while converting column "THEDATE_INTO_STR" (2799) to column "CALENDAR_YEAR1" (3657). The conversion returned status value 2 and status text "The value could not be converted because of a potential loss of data.".


What are the simple ways to convert from one data type to another? If somebody could give some example of the above...............Try using the Derived Column component to do the casting. Its more flexible than Data Conversion component.

-Jamie|||Right, you might need the flexibility of expressions in derived column.
What is the meaning of the integer as a date?|||int as a date meansI have one int type in source, which has data like20051211....
but my target column is of datetime.
Anyways, it done now...

Thanks

Data Type Confusion...

Which Datatype should i choose for Field "AGE"

Do i select "Int", "Char"?

SQL Server...in Table Desgin, The length for Int only can be max of 4 ?

Is this mean it can only store 4 digit ?

What if i want to store numbers but more then 4 digit ?

What will be the appropriate datatype to store numbers?For age, an appropriate data type would be 'int', you should however contemplate SmallDateTime if you need the full Date of Birth. An 'int' has a storage size of 4 bytes, hence 4, and can be of values from -2^31 (-2,147,483,648) through 2^31 - 1 (2,147,483,647).

Numbers can be stored using different data types, depending on what they represent and will be used for. E.g, for money, you simply use the data type 'money'.

Below are all numerics available on MS Sql Server 2000

EXACT NUMERICS
============
Integers
-------
bigint = Integer (whole number) data from -2^63 (-9223372036854775808) through 2^63-1 (9223372036854775807).

int = Integer (whole number) data from -2^31 (-2,147,483,648) through 2^31 - 1 (2,147,483,647).

smallint = Integer data from 2^15 (-32,768) through 2^15 - 1 (32,767).

tinyint = Integer data from 0 through 255.
-------
bit
-------
bit = Integer data with either a 1 or 0 value.
-------
decimal and numeric
-------
decimal = Fixed precision and scale numeric data from -10^38 +1 through 10^38 –1.

numeric = Functionally equivalent to decimal.
-------
money and smallmoney
-------
money = Monetary data values from -2^63 (-922,337,203,685,477.5808) through 2^63 - 1 (+922,337,203,685,477.5807), with accuracy to a ten-thousandth of a monetary unit.

smallmoney = Monetary data values from -214,748.3648 through +214,748.3647, with accuracy to a ten-thousandth of a monetary unit.
-------
Approximate Numerics
-------
float = Floating precision number data from -1.79E + 308 through 1.79E + 308.

real = Floating precision number data from -3.40E + 38 through 3.40E + 38.|||Hie...

Thanks alot for the info...

I just realize the Length "4" for "int" doesn't meant the total number of 4 digit...?

But how bout the Datatype "Char" or "NvarChar", the length is the number of character is it?|||you can use tinyint for AGE|||:: you can use tinyint for AGE

If you do not expect the person to live longer than a century, yeah :-) .|||::But how bout the Datatype "Char" or "NvarChar", the length is the number of character is
::it?

This is documented in the - documentation, you know.

For char and varchar fields, this is indeed the number of chars you store / can store.

Data type

Hi,
I am trying to find the data types of the fields in my table "XYZ"....Since i have 140 fields in that table, i like to store a value in INT datatype.
Does anyone it on top of their head? Really appreciate the help...

Thanks.

Do you mean a one-time query to take a peek at the data types in your table? Try this:
SELECT * FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = 'yourTable'
|||Thanks. Really appreciate your help..