I have a table that contains an nvarchar column of data. The data is actually a monetary value; sometimes with a decimal point sometimes without.
My problem is that I need to strip the decimal portion of the string if it exists. From a select statement I can use:
SUBSTRING
(DW_OBP_ORD_TMP_IC.VALUE,1,LEN(VALUE)-(LEN(VALUE)-CHARINDEX('.',DW_OBP_ORD_TMP_IC.VALUE)if a decimal point exists. But if one does not the CharIndex comes back 0 and my equation does not work correctly.
I need to pull the data from the table, along with many other fields. How do I do this without using a cursor I have millions of rows so need a solution that will be quick.
thanks in advance,
Marilyn

stripping decimal data from an nvarchar value...
TA123
Marilyn:
If you ever have to worry about whether or not the number is formatted correctly:
GJVH
select
cast(cast(value as float)as int) from tablenamedonkaiser
That will work as well.
KevinRevenueResearch
Examples:
select '45.64' as col1, cast(cast('45.64' as numeric(4,2)) as int) as col2
select '34' as col1, cast(cast('34' as numeric(4,2)) as int) as col2