?
Solved

Convert from nvarchar to int and numeric

Posted on 2012-08-16
3
Medium Priority
?
752 Views
Last Modified: 2012-08-16
Hi!

Have this stored procedure

SET QUOTED_IDENTIFIER OFF

go
CREATE PROCEDURE VEC_Artikkelimport
@PathFileName varchar(100),
@FileType int
AS

DECLARE @SQL varchar(2000)
IF @FileType = 1
 BEGIN
  SET @SQL = "BULK INSERT dbo.VEC_Fakturalinjer_TMP FROM '"+@PathFileName+"' WITH (CODEPAGE='ACP', FIELDTERMINATOR = '"";""') "
 END
ELSE
 BEGIN
  SET @SQL = "BULK INSERT dbo.VEC_Fakturalinjer_TMP FROM '"+@PathFileName+"' WITH (CODEPAGE='ACP', FIELDTERMINATOR = ';',ROWTERMINATOR = '\n') "
 END

EXEC (@SQL)

UPDATE dbo.VEC_Fakturalinjer
SET dbo.VEC_Fakturalinjer.Løpenummer = dbo.VEC_Fakturalinjer_TMP.Løpenummer,
dbo.VEC_Fakturalinjer.Vectura_materialnummer = dbo.VEC_Fakturalinjer_TMP.Vectura_materialnummer,
dbo.VEC_Fakturalinjer.Fakturert_innpris = CAST(dbo.VEC_Fakturalinjer_TMP.Fakturert_innpris,NUMERIC(12,1)),
dbo.VEC_Fakturalinjer.Enhetspris = CAST(dbo.VEC_Fakturalinjer_TMP.Enhetspris,NUMERIC(12,2)),
dbo.VEC_Fakturalinjer.Enhet = dbo.VEC_Fakturalinjer_TMP.Enhet,
dbo.VEC_Fakturalinjer.Fakturert_kvantum = CAST(dbo.VEC_Fakturalinjer_TMP.Fakturert_kvantum,NUMERIC(28,2)),
dbo.VEC_Fakturalinjer.Fakturert_volum = CAST(dbo.VEC_Fakturalinjer_TMP.Fakturert_volum,NUMERIC(28,2)),
dbo.VEC_Fakturalinjer.Vectura_kundenummer = CAST(dbo.VEC_Fakturalinjer_TMP.Vectura_kundenummer,INT),
dbo.VEC_Fakturalinjer.Vectura_kundenavn = dbo.VEC_Fakturalinjer_TMP.Vectura_kundenavn,
dbo.VEC_Fakturalinjer.Konteringsdato = CAST(dbo.VEC_Fakturalinjer_TMP.Konteringsdato,DATE),
dbo.VEC_Fakturalinjer.Vectura_bilagsnummer = dbo.VEC_Fakturalinjer_TMP.Vectura_bilagsnummer,
dbo.VEC_Fakturalinjer.EAN = CAST(dbo.VEC_Fakturalinjer_TMP.EAN,NUMERIC(28,0)),
dbo.VEC_Fakturalinjer.Kode_for_Haugen_firma = CAST(dbo.VEC_Fakturalinjer_TMP.Kode_for_Haugen_firma,INT),
dbo.VEC_Fakturalinjer.VareiAX = CAST(dbo.VEC_Fakturalinjer_TMP.VareiAX,INT)


FROM dbo.VEC_Fakturalinjer_TMP
INNER JOIN dbo.VEC_Fakturalinjer
   ON dbo.VEC_Fakturalinjer_TMP.Vectura_bilagsnummer = dbo.VEC_Fakturalinjer.Vectura_bilagsnummer

INSERT INTO dbo.VEC_Fakturalinjer (Løpenummer,Vectura_materialnummer, 
Fakturert_innpris,Enhetspris,Enhet,Fakturert_kvantum,Fakturert_volum,Vectura_kundenummer,Vectura_kundenavn,Konteringsdato,Vectura_bilagsnummer,EAN,Kode_for_Haugen_firma,VareiAX)

SELECT dbo.VEC_Fakturalinjer_TMP.Løpenummer,dbo.VEC_Fakturalinjer_TMP.Vectura_materialnummer, 
CAST(dbo.VEC_Fakturalinjer_TMP.Fakturert_innpris,NUMERIC(12,1)),CAST(dbo.VEC_Fakturalinjer_TMP.Enhetspris,NUMERIC(12,2)),
dbo.VEC_Fakturalinjer_TMP.Enhet,CAST(dbo.VEC_Fakturalinjer_TMP.Fakturert_kvantum,NUMERIC(28,2)),
CAST(dbo.VEC_Fakturalinjer_TMP.Fakturert_volum,NUMERIC(28,2)),
CAST(dbo.VEC_Fakturalinjer_TMP.Vectura_kundenummer,INT),dbo.VEC_Fakturalinjer_TMP.Vectura_kundenavn,
CAST(dbo.VEC_Fakturalinjer_TMP.Konteringsdato,DATE),dbo.VEC_Fakturalinjer_TMP.Vectura_bilagsnummer,
CAST(dbo.VEC_Fakturalinjer_TMP.EAN,NUMERIC(28,0)),CAST(dbo.VEC_Fakturalinjer_TMP.Kode_for_Haugen_firma,INT),
CAST(dbo.VEC_Fakturalinjer_TMP.VareiAX,INT)

FROM dbo.VEC_Fakturalinjer_TMP
LEFT OUTER JOIN dbo.VEC_Fakturalinjer
   ON dbo.VEC_Fakturalinjer_TMP.Vectura_bilagsnummer = dbo.VEC_Fakturalinjer.Vectura_bilagsnummer
WHERE dbo.VEC_Fakturalinjer.Vectura_bilagsnummer IS NULL

Open in new window


But gives me this error message:
 [Error Code: 195, SQL State: 42000]  'NUMERIC' is not a recognized built-in function name. 2) [Error Code: 195, SQL State: 42000]  'NUMERIC' is not a recognized built-in function name.

What is wrong ?
0
Comment
Question by:team2005
3 Comments
 
LVL 18

Accepted Solution

by:
Cluskitt earned 1000 total points
ID: 38299777
The correct syntax is CAST(dbo.VEC_Fakturalinjer_TMP.Fakturert_innpris AS NUMERIC(12,1))
0
 
LVL 16

Assisted Solution

by:EvilPostIt
EvilPostIt earned 1000 total points
ID: 38299785
CAST seems to have been used incorrectly. The syntax for cast is...

CAST ( expression AS data_type [ ( length ) ] )

Open in new window


As per the below.

http://msdn.microsoft.com/en-us/library/ms187928.aspx
0
 
LVL 2

Author Closing Comment

by:team2005
ID: 38299832
Thanks
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I have a large data set and a SSIS package. How can I load this file in multi threading?
One of the most important things in an application is the query performance. This article intends to give you good tips to improve the performance of your queries.
Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.
Suggested Courses

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question