Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Error converting data type varchar to float.

Author  Topic 

ejoeyz_85
Yak Posting Veteran

54 Posts

Posted - 2008-03-25 : 15:09:16
hello anyone... i got this message "Error converting data type varchar to float" when i was trying to insert values into table using instead of trigger...

below is my table ClimateData

quote:
USE [PVMC Database]
GO
/****** Object: Table [dbo].[ClimateData] Script Date: 03/26/2008 03:04:44 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[ClimateData](
[Climate_application_id] [uniqueidentifier] NOT NULL CONSTRAINT [DF_ClimateData_Climate_application_id] DEFAULT (newid()),
[Latitude] [float] NULL,
[Longitude] [float] NULL,
[Altitude] [varchar](50) COLLATE Latin1_General_CI_AI NULL,
[Climate_type] [varchar](100) COLLATE Latin1_General_CI_AI NULL,
[PV_application_id] [uniqueidentifier] NULL,
CONSTRAINT [PK_ClimateData_1] PRIMARY KEY CLUSTERED
(
[Climate_application_id] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]

GO
SET ANSI_PADDING OFF
GO
USE [PVMC Database]
GO
ALTER TABLE [dbo].[ClimateData] WITH CHECK ADD CONSTRAINT [FK_ClimateData_Photovoltaic] FOREIGN KEY([PV_application_id])
REFERENCES [dbo].[Photovoltaic] ([PV_application_id])
ON UPDATE CASCADE
ON DELETE CASCADE



Below is photovoltaic table

quote:
USE [PVMC Database]
GO
/****** Object: Table [dbo].[Photovoltaic] Script Date: 03/26/2008 03:06:58 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[Photovoltaic](
[PV_application_id] [uniqueidentifier] NOT NULL CONSTRAINT [DF_Photovoltaic_PV_application_id] DEFAULT (newid()),
[PV_site] [varchar](50) COLLATE Latin1_General_CI_AI NULL,
[PV_state] [varchar](50) COLLATE Latin1_General_CI_AI NULL,
[PV_type_of_system] [varchar](50) COLLATE Latin1_General_CI_AI NULL,
[PV_nominal_power] [float] NULL,
[PV_module] [varchar](150) COLLATE Latin1_General_CI_AI NULL,
[PV_mounting] [varchar](50) COLLATE Latin1_General_CI_AI NULL,
[PV_building_type] [varchar](50) COLLATE Latin1_General_CI_AI NULL,
[PV_topology] [varchar](50) COLLATE Latin1_General_CI_AI NULL,
[PV_new_or_retrofit] [varchar](50) COLLATE Latin1_General_CI_AI NULL,
[PV_period_of_design] [varchar](50) COLLATE Latin1_General_CI_AI NULL,
[PV_period_of_construction] [varchar](50) COLLATE Latin1_General_CI_AI NULL,
[PV_commissioning_date] [datetime] NULL CONSTRAINT [DF_Photovoltaic_PV_commissioning_date] DEFAULT (getdate()),
[PV_site_photo] [varbinary](max) NULL,
[PV_peak_nominal_rating] [float] NULL,
[User_application_id] [uniqueidentifier] NULL,
[Org_application_id] [uniqueidentifier] NULL,
CONSTRAINT [PK_Photovoltaic_1] PRIMARY KEY CLUSTERED
(
[PV_application_id] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]

GO
SET ANSI_PADDING OFF
GO
USE [PVMC Database]
GO
ALTER TABLE [dbo].[Photovoltaic] WITH CHECK ADD CONSTRAINT [FK_Photovoltaic_OrganizationDetail] FOREIGN KEY([Org_application_id])
REFERENCES [dbo].[OrganizationDetail] ([Org_application_id])
ON UPDATE CASCADE
ON DELETE CASCADE
GO
ALTER TABLE [dbo].[Photovoltaic] WITH CHECK ADD CONSTRAINT [FK_Photovoltaic_Users] FOREIGN KEY([User_application_id])
REFERENCES [dbo].[Users] ([User_application_id])
ON UPDATE CASCADE
ON DELETE CASCADE


Below also my command for instead of trigger


quote:
set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
go


CREATE trigger [tr_v_PhotovoltaicClimateData] on [dbo].[v_PhotovoltaicClimateData] instead of insert as
BEGIN

insert Photovoltaic (PV_site, PV_state, PV_type_of_system, PV_nominal_power, PV_module,
PV_mounting)
select distinct inserted.PV_site, inserted.PV_state, inserted.PV_type_of_system,
inserted.PV_nominal_power, inserted.PV_module, inserted.PV_mounting
from inserted left join Photovoltaic on inserted.PV_site = Photovoltaic.PV_site
and inserted.PV_state = Photovoltaic.PV_state
and inserted.PV_type_of_system = Photovoltaic.PV_type_of_system
and inserted.PV_nominal_power = Photovoltaic.PV_nominal_power
and inserted.PV_nominal_power = Photovoltaic.PV_module
and inserted.PV_nominal_power = Photovoltaic.PV_mounting
where Photovoltaic.PV_site IS NULL /*** Exclude Organization Detail already in the table ***/

insert ClimateData (Latitude, Longitude, Altitude, Climate_type, PV_application_id)
select distinct inserted.Latitude, inserted.Longitude, inserted.Altitude, inserted.Climate_type,
Photovoltaic.PV_application_id
from inserted inner join Photovoltaic on inserted.PV_site = Photovoltaic.PV_site
left join ClimateData on inserted.Latitude = ClimateData.Latitude
and inserted.Longitude = ClimateData.Longitude
and inserted.Altitude = ClimateData.Altitude
and inserted.Climate_type = ClimateData.Climate_type
where ClimateData.Latitude IS NULL /*** Exclude Organization Types already in the table ***/

END -- trigger def





and finally, i hav tried using this command to insert into table v_PhotovoltaicClimateData.. this is the command to insert

quote:
insert into v_PhotovoltaicClimateData(PV_site, PV_state, PV_type_of_system, PV_nominal_power,
PV_module, PV_mounting, Latitude, Longitude, Altitude, Climate_type)
values ('CETDEM', 'Sequ Inspection', 'Cheras', 34.44, 'ew', 'ewew',
34343.44, 323.32, 'ewew', 'ewewe')


and i got this error...

quote:
Msg 8114, Level 16, State 5, Procedure tr_v_PhotovoltaicClimateData, Line 6
Error converting data type varchar to float.




so anyone... plzz help me...

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-03-25 : 15:17:20
Can you provide DDL for v_PhotovoltaicClimateData as well? it seems like you are trying to populate a varchar value to a float type column.
Go to Top of Page

ejoeyz_85
Yak Posting Veteran

54 Posts

Posted - 2008-03-25 : 15:26:42
i have no DDL... the prob here is how to convert data type varchar to float....
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-03-25 : 15:29:21
use CAST() to cast it to float. Cant understand why you dont have DDL? DDL means table structure just as you posted for other two tables.
Go to Top of Page

ejoeyz_85
Yak Posting Veteran

54 Posts

Posted - 2008-03-25 : 15:33:36
use cast() ?? how visakh? in where?
Go to Top of Page

ejoeyz_85
Yak Posting Veteran

54 Posts

Posted - 2008-03-25 : 15:46:02
see my structure

<a href="http://allyoucanupload.webshots.com/v/2002713281215751145"><img border="0" src="http://aycu35.webshots.com/image/46474/2002713281215751145_rs.jpg" alt="Free Image Hosting at allyoucanupload.com"/></a>


<a href="http://allyoucanupload.webshots.com/v/2002770590529628334"><img border="0" src="http://aycu17.webshots.com/image/47216/2002770590529628334_rs.jpg" alt="Free Image Hosting at allyoucanupload.com"/></a>
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-03-25 : 15:51:30
Structure looks ok. Can you change like this?
insert into v_PhotovoltaicClimateData(PV_site, PV_state, PV_type_of_system, PV_nominal_power,
PV_module, PV_mounting, Latitude, Longitude, Altitude, Climate_type)
values ('CETDEM', 'Sequ Inspection', 'Cheras', CAST(34.44 AS float), 'ew', 'ewew',
34343.44, 323.32, 'ewew', 'ewewe')
Go to Top of Page

ejoeyz_85
Yak Posting Veteran

54 Posts

Posted - 2008-03-25 : 15:59:16
visakh.. i still got the same error...

Msg 8114, Level 16, State 5, Procedure tr_v_PhotovoltaicClimateData, Line 5
Error converting data type varchar to float.


Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-03-25 : 16:04:35
then error is somewhere else.
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2008-03-25 : 16:05:26
How can last "ewew" be an altitude?

insert into v_PhotovoltaicClimateData(PV_site, PV_state, PV_type_of_system, PV_nominal_power,
PV_module, PV_mounting, Latitude, Longitude, Altitude, Climate_type)
values ('CETDEM', 'Sequ Inspection', 'Cheras', 34.44, 'ew', 'ewew',
34343.44, 323.32, 'ewew', 'ewewe')


E 12°55'05.25"
N 56°04'39.16"
Go to Top of Page

ejoeyz_85
Yak Posting Veteran

54 Posts

Posted - 2008-03-25 : 16:07:45
altitude i put VARCHAR because for example...

i will insert data like this.. 30 metres above sea level...
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-03-25 : 16:08:25
Didnt spot that one
Go to Top of Page

ejoeyz_85
Yak Posting Veteran

54 Posts

Posted - 2008-03-25 : 16:09:36
errmm.. what shud i do?? i hav no idea...
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2008-03-25 : 16:13:01
Also, v_PhotovoltaicClimateData doesn't exist in any of the DDLs above.

Table PhotovoltaicClimateData does, but not the view(?) v_PhotovoltaicClimateData.



E 12°55'05.25"
N 56°04'39.16"
Go to Top of Page

ejoeyz_85
Yak Posting Veteran

54 Posts

Posted - 2008-03-25 : 16:18:17
i forgot to show... i also hav view table v_PhotovoltaicClimateData..
see this structure

<a href="http://allyoucanupload.webshots.com/v/2005053021185074206"><img border="0" src="http://aycu13.webshots.com/image/50012/2005053021185074206_rs.jpg" alt="Free Image Hosting at allyoucanupload.com"/></a>
Go to Top of Page

ejoeyz_85
Yak Posting Veteran

54 Posts

Posted - 2008-03-26 : 01:53:30
help me???
Go to Top of Page

ejoeyz_85
Yak Posting Veteran

54 Posts

Posted - 2008-03-26 : 11:47:58
anyone????
Go to Top of Page

ejoeyz_85
Yak Posting Veteran

54 Posts

Posted - 2008-03-28 : 03:11:47
comon...plz.. i've tried many time...
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2008-03-28 : 03:18:46
Read this article, foloow all steps and post again.
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx


E 12°55'05.25"
N 56°04'39.16"
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2008-03-28 : 12:08:32
Obviously continued here
http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=99861



E 12°55'05.25"
N 56°04'39.16"
Go to Top of Page
   

- Advertisement -