2012年3月27日星期二

float in VB-Skript

Hi there
I have two Databases
in both databases are fields with float - no null
If I am transfering data from one database to the other everything works well unless there is a comma in the field ( 0,99 or 123,456 )

"SQLAString = "Insert into InventurDaten (Artikelnummer,Hauptartikelnummer,Auspraegung,Arti kelbezeichnung,Artikeltext1,EDVEingang ,EDVAusgang,InventurmengeEDV) values ('" & ArtNr & "','" & ArtNrT & "','" & AP & "','" & ArtBez & "','" & ArtText & "'," & EDVEingang & "," & EDVAusgang & "," & ArtMenge & ")"
"
where EDVEingang and EDVAusgang are defined as float, no null

Then the programm stops with the following message:
Within the INSERT-Procedure there are less columns then there are Contents in the Value-Clause.

I have to finish the programm until tomorrow morning and don't know what the problem is.

If anybody has an idea, please let me know.

regards
Reineruse cast(columnname as float) to avoid this kind of errors !!!|||Thanks for your quick answer,
but if I'm trying this :
SQLAString = "Insert into InventurDaten (Artikelnummer,Hauptartikelnummer,Auspraegung,Arti kelbezeichnung,Artikeltext1,cast(EDVEingang as float),EDVAusgang,InventurmengeEDV) values ('" & ArtNr & "','" & ArtNrT & "','" & AP & "','" & ArtBez & "','" & ArtText & "'," & EDVEingang & "," & EDVAusgang & "," & ArtMenge & ")"

I'm getting the error: Wrong Syntas near "("

regards|||SQLAString = "Insert into InventurDaten (Artikelnummer,Hauptartikelnummer,Auspraegung,Arti
kelbezeichnung,Artikeltext1,cast(EDVEingang as float),EDVAusgang,InventurmengeEDV) values ('" & ArtNr & "','" & ArtNrT & "','" & AP & "','" & ArtBez & "','" & ArtText & "'," & "EDVEingang & "," & EDVAusgang & "," & ArtMenge & ")"

You need to use this
SQLAString = "Insert into InventurDaten (Artikelnummer,Hauptartikelnummer,Auspraegung,Arti
kelbezeichnung,Artikeltext1,EDVEingang,EDVAusgang, InventurmengeEDV) values ('" & ArtNr & "','" & ArtNrT & "','" & AP & "','" & ArtBez & "','" & ArtText & "'," & "cast (" & EDVEingang &" as float) ," & EDVAusgang & "," & ArtMenge & ")"|||Originally posted by Enigma
You need to use this
SQLAString = "Insert into InventurDaten (Artikelnummer,Hauptartikelnummer,Auspraegung,Arti
kelbezeichnung,Artikeltext1,EDVEingang,EDVAusgang, InventurmengeEDV) values ('" & ArtNr & "','" & ArtNrT & "','" & AP & "','" & ArtBez & "','" & ArtText & "'," & "cast (" & EDVEingang &" as float) ," & EDVAusgang & "," & ArtMenge & ")"

Thanks again.
I did as you advised and got the error : wrong syntas near "as"

SQLAString = "Insert into InventurDaten (Artikelnummer,Hauptartikelnummer,Auspraegung,Arti kelbezeichnung,Artikeltext1,EDVEingang,EDVAusgang, InventurmengeEDV) values ('" & ArtNr & "','" & ArtNrT & "','" & AP & "','" & ArtBez & "','" & ArtText & "'," & "cast (" & EDVEingang & " as float)," & EDVAusgang & "," & ArtMenge & ")"|||Try this

SQLAString = "Insert into InventurDaten (Artikelnummer,Hauptartikelnummer,Auspraegung,Arti
kelbezeichnung,Artikeltext1,EDVEingang,EDVAusgang,
InventurmengeEDV) values ('" & ArtNr & "','" & ArtNrT & "','" & AP & "','" & ArtBez & "','" & ArtText & "'," & "convert(float," & EDVEingang & ")," & EDVAusgang & "," & ArtMenge & ")"|||Originally posted by Enigma
Try this

SQLAString = "Insert into InventurDaten (Artikelnummer,Hauptartikelnummer,Auspraegung,Arti
kelbezeichnung,Artikeltext1,EDVEingang,EDVAusgang,
InventurmengeEDV) values ('" & ArtNr & "','" & ArtNrT & "','" & AP & "','" & ArtBez & "','" & ArtText & "'," & "convert(float," & EDVEingang & ")," & EDVAusgang & "," & ArtMenge & ")"

I have tried this. No error is coming up any more, but all decimal values are rounded: 263,2569 => 263 142,7402 => 142|||Originally posted by ReinerS
I have tried this. No error is coming up any more, but all decimal values are rounded: 263,2569 => 263 142,7402 => 142

Is there anybody who has an idea about the problem with the figures after the decimal point?|||You sure?

What's the DDL of the Table?|||Originally posted by Brett Kaiser
You sure?

What's the DDL of the Table?

What do you mean with DDL of the Table|||Data Definition Language (DDL)...

Go to Enterprise Manager (EM) right click on the table go to all tasks, script database...preview Copy and paste the CREATE TABLE myTable99 (Col1 int, ect...

statement here...|||Originally posted by ReinerS
Thanks again.
I did as you advised and got the error : wrong syntas near "as"
SQLAString = "Insert into InventurDaten (Artikelnummer,Hauptartikelnummer,Auspraegung,Arti kelbezeichnung,Artikeltext1,EDVEingang,EDVAusgang, InventurmengeEDV) values ('" & ArtNr & "','" & ArtNrT & "','" & AP & "','" & ArtBez & "','" & ArtText & "'," & "cast (" & EDVEingang & " as float)," & EDVAusgang & "," & ArtMenge & ")"

I suspect that "cast .. as .." was intended to be a visual basic function-call not part of the SQL statement but I'm not quite sure.

Is the "locale" setting for this workstation in-sync with what the SQL server expects?

The bottom line is: Different countries obviously use different meanings for "," vs. "." in a number and both the DBMS and the workstation should, in their own way, be prepared to handle it once you (in the appropriate way, whatever it is) tell them to do so. There may be options that you can set for one of the connection objects. Look for "national language" and so-on in the various pieces of documentation/help. Or "internationalization."

This is a classic internationalization-issue, and it has been "solved."|||Originally posted by Brett Kaiser
Data Definition Language (DDL)...

Go to Enterprise Manager (EM) right click on the table go to all tasks, script database...preview Copy and paste the CREATE TABLE myTable99 (Col1 int, ect...

statement here...

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[InventurDaten]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[InventurDaten]
GO

CREATE TABLE [dbo].[InventurDaten] (
[Artikelnummer] [varchar] (50) COLLATE Latin1_General_CI_AS NULL ,
[Hauptartikelnummer] [varchar] (50) COLLATE Latin1_General_CI_AS NULL ,
[Auspraegung] [varchar] (50) COLLATE Latin1_General_CI_AS NULL ,
[Artikelbezeichnung] [varchar] (100) COLLATE Latin1_General_CI_AS NULL ,
[Artikeltext1] [varchar] (100) COLLATE Latin1_General_CI_AS NULL ,
[EDVEingang] [float] NULL ,
[EDVAusgang] [float] NULL ,
[InventurmengeEDV] [float] NULL ,
[Inventurdatum] [datetime] NULL ,
[Inventurzaehlmenge] [float] NULL ,
[Inventurdifferenz] [float] NULL ,
[EKPreis] [float] NULL ,
[Inventurbetrag] [float] NULL ,
[Inventurdifferenzbetrag] [float] NULL ,
[EDVWertEingang] [float] NULL ,
[EDVWertAusgang] [float] NULL ,
[EDVUmsatzJahr] [float] NULL ,
[EDVRohertragJahr] [float] NULL ,
[EDVEinstandspreis] [float] NULL ,
[EDVRabatte] [float] NULL ,
[EDVWertProduktion] [float] NULL ,
[EDVMengeProduktion] [float] NULL ,
[EDVBezugskosten] [float] NULL
) ON [PRIMARY]
GO|||Please post the ddl for both tables.|||Originally posted by rnealejr
Please post the ddl for both tables.

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[T0302003]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[T0302003]
GO

CREATE TABLE [dbo].[T0302003] (
[C008] [float] NOT NULL ,
[C009] [float] NOT NULL ,
[C012] [float] NOT NULL ,
[C013] [float] NOT NULL ,
[C015] [varchar] (30) COLLATE Latin1_General_CI_AS NOT NULL ,
[C017] [float] NOT NULL ,
[C018] [float] NOT NULL ,
[C019] [float] NOT NULL ,
[C021] [datetime] NULL ,
[C022] [datetime] NULL ,
[C024] [float] NOT NULL ,
[C026] [float] NOT NULL ,
[C031] [float] NOT NULL ,
[C032] [varchar] (1) COLLATE Latin1_General_CI_AS NULL ,
[C033] [float] NOT NULL ,
[C034] [float] NOT NULL ,
[C042] [float] NOT NULL ,
[C044] [float] NOT NULL ,
[C054] [float] NOT NULL ,
[C059] [float] NOT NULL ,
[C060] [datetime] NULL ,
[C079] [int] NOT NULL ,
[C100] [varchar] (1) COLLATE Latin1_General_CI_AS NULL ,
[C101] [datetime] NULL ,
[C102] [float] NOT NULL ,
[C103] [varchar] (20) COLLATE Latin1_General_CI_AS NULL ,
[C104] [datetime] NULL ,
[C105] [varchar] (20) COLLATE Latin1_General_CI_AS NULL ,
[C118] [float] NOT NULL ,
[C119] [float] NOT NULL ,
[C120] [float] NOT NULL ,
[ts] [timestamp] NULL
) ON [PRIMARY]
GO

[C012] => EDVWertEingang
[C013] => EDVWertAusgang|||Where are the values "& EDVEingang & "," & EDVAusgang " coming from that you are using in your insert statement and what data types are these in your vbscript ?|||Originally posted by rnealejr
Where are the values "& EDVEingang & "," & EDVAusgang " coming from that you are using in your insert statement and what data types are these in your vbscript ?

SQLString = "Select C008, C009, C012, C013, C015, C024, C026, C031, C033, C042, C044, C102 from T0302003"

EDVWertEingang = DoArtikel("C012")
EDVWertAusgang = DoArtikel("C013")

types are not declared|||When you perform this select in query analyzer, what do the float values look like that are returned ? Also, in this same table, if you insert a value like 3.456, will it accept it and what is returned by query analyzer if it is inserted successfully ?|||Originally posted by rnealejr
When you perform this select in query analyzer, what do the float values look like that are returned ? Also, in this same table, if you insert a value like 3.456, will it accept it and what is returned by query analyzer if it is inserted successfully ?

Result from query

Select C008, C009, C012, C013, C015, C024, C026, C031, C033, C042, C044, C102 from T0302003

225.0 147.0 263.25689999999997 171.9949 100121010H 316.05000000000001 144.05510000000001 1.170026 0.0 0.0 0.0 0.0|||Originally posted by ReinerS
Result from query

Select C008, C009, C012, C013, C015, C024, C026, C031, C033, C042, C044, C102 from T0302003

225.0 147.0 263.25689999999997 171.9949 100121010H 316.05000000000001 144.05510000000001 1.170026 0.0
0.0 0.0 0.0

Insert into Inventurdaten (Artikelnummer, EDVWertEingang) values ( 111111, 14.123123)

111111 NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL NULL 14.123123 NULL NULL NULL NULL NULL NULL NULL NULL|||In your vbscript you can use the replace function - to replace the comma with a period.|||Originally posted by ReinerS

EDVWertEingang = DoArtikel("C012")
EDVWertAusgang = DoArtikel("C013")

types are not declared


Does that mean they are variant by default?

Why not declare them as float?|||Originally posted by Brett Kaiser
Does that mean they are variant by default?

Why not declare them as float?

I have already tried to declare them as float, but vbscript does not know float

How do I replace the comma by a point?|||I think Brett means single or double.|||Originally posted by ReinerS
I have already tried to declare them as float, but vbscript does not know float

How do I replace the comma by a point?

I found the replace command and...

you're great

it works

Thanks a lot|||replace(xxxx,",",".")|||Originally posted by rnealejr
I think Brett means single or double.

You would think he means that

What a maroon

what a gull-a-bull|||Dang ReinerS - you kept responding when I was responding.

Happy to help.

没有评论:

发表评论