How To Convert Numeric To Character In CURSOR

Aug 19, 2005

Hi All there -
I want to show the o/p of a cursor on a single line. There is a numeric variable that needs to be clubed with the character variable. If I use char() the o/p is not right.
How do I do that?

View 3 Replies


ADVERTISEMENT

Convert Character Field To Numeric

Jan 1, 2015

I have one table and this field is character field with save data in below.

Bonus_table->bonus_amt_field. Char(20)
======================================
Record information
0
Null
Blank
3
4
Null
Blank

if i want to convert this character field => change to numeric field to display ,how to handle "Blank" and "null" record?

The result expect:
0
0
0
3
4
0
0

I try this query but wrong message :

select cast(convert(numeric,3)bonus_amt) as bonus_amt
from test

View 2 Replies View Related

Character Or Numeric As PK

Mar 14, 2001

Hello,
I am from the school of thought that you should in every case have your primary keys as numeric values only. However, where I currently work there is a project leader who is a recent FoxPro convert (I know, they are tough ones to crack). I made the suggestion recently that the keys in the table should be numeric and with him being the project leader and me just a lowely developer he said get lost. I made the point that later joining your tables together in a PK/FK relationship where the keys where character would be slower then with numeric keys. He didn't listen and now we are approaching production with a database that is really just a bunch of text file. He said that with SQL 7 it doesn't matter if the pk is numeric or character. I disagree. But I need solid documentation to take to him and to the managers to convince them. If anyone out there could advise me on this. And if anyone could give me or tell me where I could find documentation on why even in SQL 7 there is a need to use numeric keys that would be a great help and you would be making one more shop in this world a little bit more technically sound :-) Thank you in advance for your help.

kc

View 1 Replies View Related

Numeric Value Only For A Character Field

Aug 2, 2007

HiI have a character field (char ot varchar) that I want to force only tocontain numeric characters.Can that be done by way of defining a constraint on the field ?or by any other way in the field/table definition ?What id the syntax ?Anyone have examples ?ThanksDavid Greenberg

View 1 Replies View Related

Get Index Of First Alpha-numeric Character

Sep 29, 2005

In SQL I need to be able to take a varchar parameter @Area and convert it to a float.

The input values for @Area I can't control. They can range from 6300 to 6,300 SqFt to 1.2 Acres .

So to convert this value to a float I basically look through the string and remove everything that isn't a number or a period. Then I would convert this value to square feet based on how large the number is.


Code:

DECLARE @k int, @Temp VarChar(25), @SqFt Float
SELECT@Temp = @Area
select @Temp

select @k = patindex('%[^0-9. ]%', @Temp)
while @k> 0
begin
select @Temp = replace(@Temp, substring(@Temp, @k, 1), '')
select @k= patindex('%[^0-9. ]%', @Temp)
end

If @Temp = ''
BEGIN
SET @Temp = '0'
END

SELECT @SqFt = Convert(Float, @Temp)

--Distinguish if it was acres or square feet
If (@SqFt > 750.00)
BEGIN
SET @SqFt = @SqFt
END
ELSE
BEGIN
SET @SqFt = (@SqFt * Convert(Float,43560) )
END

SELECT @SqFt



This works great except for one situation, If @Area is something like 6,300 Sq.Ft. . When I run it through the part that removes all non-numeric items and periods, I end up with 6300 .. . So to get around this I want to find the first letter in the string and then remove everything after it. Then take the result and run it through part that removes everything but the numbers and period.

However I can't find away to get the index of the alpha-numeric character and remove everything after it.

Thanks in advance!

View 1 Replies View Related

Script To Strip Data From First Non-numeric Character

Jul 5, 2002

I need a script to find the position of the first non-numeric in a telno field and delete from that point onwards.

Example: 01208 12345 (Work) would become 01208 12345

Has anybody come across this before ?

TIA

Neil.

View 1 Replies View Related

Excluding Character From A Numeric String X34820

Sep 13, 2001

hi I have a table which contain an id field as a char(20)
The content of this field is combination of string and numbers as follow

id flag
--------- -----
38383
88585
18834
x4820
z4892
t9494

I need to update the flag field where first character in the id field is not numeric. HOw can I do that.
thanks for your hlep

Thanks

AL

View 2 Replies View Related

Character To Numeric Conversion Error- Select Statment On Char Column

Sep 18, 2007

Hi guys/ladies I'm still having some trouble formatting a select statement correctly.
I am using a sqldatasource control on an aspx page. It is connecting via odbc string to an Informix database.
Here is my select statement cut down to the most basic elements.
SELECT     commentFROM         informix.ipr_stucomWHERE     (comment > 70)
The column "comment" contains student grades ranging from 0-100 and the letters I, EE, P, F, etc. Therefore the column is of a char type. This is a problem because I cannot run the above statement without hitting an alpha record and getting the following error
"Character to numeric conversion error"
How can I write this statement where it will work in the datasource control and have it only look at numeric values and skip the alpha values?
I have tried case with cast and isnumeric... I don't think that I have the formating correct.
I have also used:
WHERE (NOT (comment = '  I' OR comment = ' EE' OR comment = ' NG' OR comment = ' WP' OR comment = ' WF' OR comment = '  P' OR comment = '  F'))
This works but is very clunky and could possibly break if other letters are input in the future. There has to be a better way.I am sorry for my ignorance and thanks again for your help.

View 2 Replies View Related

Convert Int Value To A Numeric.

Mar 12, 2008

Hi--

Got a column with int value and I need to sum the entire column by converting to a numeric.-- here what I have

select isnull(convert(varchar(15),sum(cast(columnName as numeric))),'0.00') from myTable-- But my outcome doesnt have decimal 0.00

any help?


Josephine

View 2 Replies View Related

How To Convert Varchar To Numeric ?

Jul 20, 2005

I have imported data from excel file. When data came to SQL table, the typeof AMOUNT column was varchar. I tried to convert and cast amount type ofamount column to number type but it does not allow me to convert.What is the best way of importing data into SQL and type stays the same asit was in excel file ?Or anyone has any better solution, please let me.Thanks.

View 4 Replies View Related

Convert String To Numeric

Jul 29, 2007



Hi all,
I defined an user string type varible in the package as AccountLen. I am trying to use this varible in the Expression of Derived Column transformation.
I want to retrieve a part of column, i.e: Right(Column1, @AccountLen), this is always wrong because the AccountLen is string type. How I can convert it to the numeric so that can be used in the RIGHT function?
Thanks

View 3 Replies View Related

Convert Float To Numeric Error..... HELP!

Jan 23, 2002

I'm running the following statement...

The column is currently float (8). Need to convert to numeric. I've tried cast, convert. no go for either.

Any help on this would be greatly appreciated.

..... select ... convert(numeric(38,0), colname)


TIA,

Jeremy

View 1 Replies View Related

How Can I Convert Binary(16) To Integer Or Numeric?

Feb 16, 2006

HI!!!:shocked:

Im trying to convert 0x00085180F0A2D511B69600508BE96424 to Integer or numeric format.

I just tried, At to many forms and combinations of that query
Help me !!!

SELECT CAST(CAST(CAST("field name " AS nvarchar) AS varbinary) AS float)

select cast(cast("field name " as varbinary)as integer)

select convert(int," field name") from FILE

select convert(varchar," field name") from FILE



The only answer that I have is
-1947638748 or ‘ ‘ or

And if I try with to many rows of the field at the same format,
It Answer me the same: -1947638748 for all the rows.

Thank`s for all

View 5 Replies View Related

Datatype Convert Char To Numeric

Dec 31, 2003

Hi,

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... ;-)

best regards and have fun with new year eve.

Michael

View 8 Replies View Related

T-SQL (SS2K8) :: Convert Numeric Value To CHAR(7)

Sep 22, 2014

I have to store the result of a calculation in a column of type CHAR(7) (and am unable to change the column type).

The calculation can have results ranging in size from 0.1234567 to 99999999.

In the first case, I would need to store the value of 0.12345 in the column. In the later case, an error should be thrown.

So I need to store all of the significant digits from the left of the decimal (if there are < 7) and as many of the digits to the right as will fit into a CHAR(7), with the remaining precision being truncated.

View 6 Replies View Related

Error To Convert Nvarchar To Numeric

Aug 15, 2013

I am hitting error to convert nvarchar to numeric.

my data as below:

2721.000000000000

How can I convert to be just 2721?

View 3 Replies View Related

How To Convert Null To Currency Or Numeric

May 12, 2006

Greetings -

I have a problem that I am unable to fix. I am migrating data from one ERP system to another ERP system.

I created a table in SQL via DTS by converting an excel file into an SQL Table.

The table has a column 'currentcost'. Most items in the table have a value in this column. However, some items have <null> in this column. I am updating another SQL table with currentcost that is in this column. However, my table being updated requires a value in its corresponding currentcost table. Therefore, my update statement terminates due to the source table having <null> values.

I tried an update statement to convert <null> into a '0'

It was 'update Source_New_ItemMaster set currentcost = '0' where currentcost = <null>

This obviously didn't work. How can a change a <null> value in an SQL table to '0' (zero)?

View 3 Replies View Related

How To Convert From CHAR To Numeric In The Table

Sep 29, 2005

I have imported some data to sql2k from my old system. Somehow, it importedinvoice amount to char type.I just created another column called invamt2 type NUMERIC so I can copy orconvert content of invamt which is type CHAR. There are about 50,000records.How can I convert/cast from char type to numeric type ?Thanks

View 2 Replies View Related

Cannot Convert Varchar To Numeric Issue

Jul 20, 2005

Hi again all,I have a small issue. Here's an example dataset :F1 F2 F31 0.58 Hi2 0.70 Hello3 Fail Bye4 <Null> HiWhen I write this statement :SELECT SUM(CONVERT(DECIMAL(16,8),F2)) MySumFROM T1WHERE IsNumeric(IsNull(F2,'X'))=1I get "Cannot convert a Varchar value to Numeric" error. From what Iunderstand, it somehow tries to convert to a decimal(16,8) BEFORE filteringthe nulls and the non-numeric out. (Keep in mind that the actual table hasover 1.5Million records).Any idea on how to get around that ?Thanks,Michel

View 1 Replies View Related

Convert Numeric Date To DateTime

Apr 29, 2008

Hello,
I have a column called 'FileDate' that is NUMERIC (18,0). The format is YMMDD. A sample of March 1st and 2nd, 2008:

80301
80302

Is there a way to convert/cast this to DateTime or SmallDateTime?

Thank you for your help!

cdun2

View 5 Replies View Related

Help Needed To Convert Char To Numeric

Feb 5, 2008



Hi ,

I am trying to convert a char field of lenght 5 into numeric (5,2) 999.99 format ,
i am getting an arithmentic overflow error.

The Character Data is 5 in length

It works fine if the Data is 00000
it fails if there is any number in the data

Like 10000
or 05000

How do i represent these into Numeric (5,2)

please let me know what taransformation to use and how.

Thanks,

View 2 Replies View Related

How I Convert Varchar Sal Field To Numeric In Query

Feb 1, 2006

how i convert varchar sal field to numeric in query
select sum(sal) from emp1
error:the sum or average aggregate operation cannot take a varchar data type as an argument.

View 1 Replies View Related

How Can I Conserve The Initial Zero When Convert Numeric To String Using STR()

May 28, 2006

Sorry to raise a stupid question but I tried many methods which didwork.how can I conserve the initial zero when I try to convert STR(06) intostring in SQL statment?It always gives me 6 instead of 06.Thanks a lot.

View 15 Replies View Related

CURSOR - Conversion Failed When Converting Date And / Or Time From Character String

May 15, 2015

This is my code and I don't know why this error keeps coming out : PS : I did cursor to execute query.Th error showed is bold:

DECLARE RegCreatedDate CURSOR FOR
SELECT DISTINCT (CONVERT(NVARCHAR,CreatedDate,103)) 
FROM CA_Registration WHERE Month(CreatedDate)= @paMonthIn AND YEAR(CreatedDate)=@paYearIn
OPEN RegCreatedDate
FETCH NEXT FROM RegCreatedDate INTO @RegCreatedDate
WHILE @@FETCH_STATUS = 0

[Code] ....

View 9 Replies View Related

Convert Character To Datetime

Nov 9, 2007

Hi

I have column as month and value as January, february. etcc....

can we convert this character column into date&time format.. if we do that what will be output..

I am doing test instance, when i sort by month column it's sorted in alphabetical order. when we convert this into date&time, it's sorts by date&time, it puts me right direction..

i dont know can we do this or not..

thanks
phani

View 2 Replies View Related

Convert Character To NULL

Jun 7, 2007



I am loading a flat file to a table but I also need to scrub the data a bit before the data hits the table. The main update required is converting a dot (.) character to a null value. The source file is using this character to indicate a blank. I know I can use the Dervived Column Transformation, but I have quite a few columns which will take a while to manually configure. Is there another transformation option that anyone can point me to?



Thanks

View 10 Replies View Related

Convert With Character Field And Datetime

Jan 29, 2007

Hi,

I am getting a date string that is contained in a character field (char(20)).

An example of the data is as follows:

2005-09-20121315001

it is in the format YYYY-MM-DDHHMMSSMMM.

I want to insert this value into a datetime field. I have used convert, but can only insert it when I split out the time portion and separate them with a colon

i.e. to get it to insert into a datetime field the data has to be in the following format

2005-09-20 13:15:18.001

YYYY-MM-DD HH:MM:SS.MMM

Is there a style parameter in the convert function that will allow me to insert this value without having to separate the hours/minutes/seconds with a colon? I have tried BOL but it seems that all the examples have colons in them where there is a time portion to the date,

Thanks in advance

View 1 Replies View Related

Convert Character Data To Datetime

Aug 16, 2006

Hi! I need to insert character data into a SQL 2005 table in the datetime format. The strings I need to convert are in the following format: ddmmyyyy

I tried using case and convert:

cast('08162006' as datetime))
convert(datetime,'08162006',101))

Both attempts fail with the following error:

The conversion of a char data type to a datetime data type resulted in an out-of-range datetime value.

Any advice is greatly appreciated. Thanks.

View 10 Replies View Related

Need To Convert Cursor

Dec 11, 2006

I am new to SQL and have created a stored procedure for a .net webapplication. Unfortunately I had to use a cursor in the storedprocedure, so it is taking several minutes to execute because it has toread through about 15,000 records. There must be another way to dowhat I'm trying to do without a cursor. I've tried temp tables andcase statements, but I can't seem to get them to work. I've beentrying to figure this out for over a week and I am just running into awall. Some expert advise would be much appreciated. My code is below.Thank you in advance.--Insert records into first temp tableDECLARE @tempA TABLE(lnkey varchar(10),AuditorIDvarchar(7))INSERT INTO @tempASELECTLNKEY,AuditorIDFROMdbo.tblALPSLoansWHERE AuditDate BETWEEN @BegDate AND @EndDate --parameters from myapplicationAND AuditorID IN (SELECT LANID FROM dbo.tblEmployees WHERE ACTIONTYPE ='ADDED')AND AuditType = @AuditType --parameter from my application--Insert percentage value of Pre-Funding completes for each auditorinto temp table BDECLARE @tempB TABLE(LnkeyCount int,AuditorIDvarchar(7))INSERT INTO @tempBSELECTROUND(COUNT(LNKEY) * @Percent/100, 0) AS 'LnkeyCount',AuditorIDFROM dbo.tblALPSLoansWHERE AuditDate BETWEEN @BegDate AND @EndDateAND AuditorID IN (SELECT LANID FROM dbo.tblEmployees WHERE ACTIONTYPE ='ADDED')GROUP BY AuditorID/*Create cursor to loop through records and add a loan number totblinjectloans if the number of loans in tblinjectloans for eachauditor is less than the percentage value for each auditor from@tempB*/DECLARE @lnkey varchar(10)DECLARE @AuditorID varchar(7)DECLARE @var1intDECLARE @var2intDECLARE @sqlvarchar(4000)DECLARE c1 CURSOR FORSELECT lnkey, auditoridFROM @TempAOPEN c1FETCH NEXT FROM c1INTO @LNKEY, @AuditorIDWHILE @@FETCH_STATUS = 0BEGINSelect @var1 = COUNT(Lnkey) from dbo.tblInjectLoans whereAuditorID=@AuditorIDSelect @var2 = LnkeyCount from @tempB where AuditorID=@AuditorIDIF @var1 < @var2Insert into dbo.tblInjectLoans(lnkey, AuditorID)Values (@LNKEY, @AuditorID)FETCH NEXT FROM c1INTO @LNKEY, @AuditorIDENDCLOSE c1DEALLOCATE c1

View 8 Replies View Related

Transact SQL :: How To Convert Numeric Data Type To A Varchar With No Decimal Place

Aug 31, 2015

So my data is delivered as numeric(9,2)...like 100.00. I have to extract that data and store it as a varchar 0 filled without the decimal place...like 0000010000///I tried the following and it did not work...

RIGHT('000000000'+CONVERT(VARCHAR,[EODPosting].[Amount]),10),

View 8 Replies View Related

Convert Character String To Date &&amp; Use In Calcs.

Apr 21, 2008



Hi There,

I am trying to create a report that sums up new cases weekly based on the previous 5 months. I have included some sample data below. The only field that displays a date is called monthSubmitted, varchar 7 and not very useful. How can I first convert this firld to a date ddmmyy?

How would you the code it so the user can run the report on demand at any given time and display the data for the last 5 months on a weekly basis? I am not sure as to how the date calculations should be coded.










12-Jan
19-Jan
26-Jan
2-Feb
9-Feb
16-Feb
23-Feb

MSS








New Cases Received
85
84
79
98
79
95
65

S1
30
32
27
40
42
38
29







S2
47
34
37
23
23
37
32

S3
3
7
-
17
4
1
9



Thanks,
Rhonda

View 5 Replies View Related

Convert Character Representation Of A Signed Decimal

Apr 25, 2008

SQL/SERVER 2000:

Data transform task which copies data from a text file to a db table.

Text file field value = 0000000242E (signed decimal)

DB column data type = decimal(11,2)

How do I get this value correctly converted? Getting "invalid data value" error message.

thanks for any help

View 1 Replies View Related

Reporting Services :: How To Convert Character Value Into Number Value

Aug 2, 2009

I have a field that contains number but it actually is character. I want to convert it to number so i can put it into query like this:

sum(field) as Totalmyfield.

View 6 Replies View Related







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