We help IT Professionals succeed at work.
Get Started

Convert from nvarchar to int and numeric

785 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 ?
Comment
Watch Question
Commented:
This problem has been solved!
Unlock 2 Answers and 3 Comments.
See Answers
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE