Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Replacing one field with the numeric equivalent of a fie
Message
 
To
26/03/2008 15:39:28
General information
Forum:
Microsoft SQL Server
Category:
Other
Miscellaneous
Thread ID:
01305881
Message ID:
01305936
Views:
11
>>It means that Field1 has values that cannot be converted to numeric(20,0).
>
>I have some records that have an empty values on Field1. So, that might be the reason. So, in order to achieve a complete conversion, I would have to put "0" in those empty values. Then, I can replace them with "" after.
>
>Thanks

BTW why you need Numeric(20)?
Wouldn't BIGINT work for you?
THAT is 20 bytes for record! BigInt is only 8 bytes and it is 2^63?
But you know your data better :-)
DECLARE @Test TABLE (Fld1 varchar(200), fld2 numeric(10))
INSERT INTO @Test VALUES ('1',0)
INSERT INTO @Test VALUES ('1e1',0)
INSERT INTO @Test VALUES ('1d12',0)
INSERT INTO @Test VALUES ('',0)

UPDATE @Test SET Fld2 = CAST(Fld1 as int)
WHERE ISNUMERIC(Fld1+'0e1') = 1

SELECT * FROM @Test
Against Stupidity the Gods themselves Contend in Vain - Johann Christoph Friedrich von Schiller
The only thing normal about database guys is their tables.
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform