SQL 2008 query changes '10' into '3-' or '2-'
Hello I got problem with SQL 2008 (10.0.4000) using: SELECT TOP 1000 [ROK] ,[obroty] ,[NmrGrupy] ,[NmrTematu] ,[NmrZak] FROM [plan].[dbo].[rozlicz] where NmrGrupy = 10 gives me : Msg 245, Level 16, State 1, Line 2 Conversion failed when converting the varchar value '3-' to data type int. and it's about '10' from where statement, same with '31' but usign f.e. '11','12' gives me results without error tia
August 20th, 2011 9:40am

Unless there is a data conversion or a DML statement this should not occur . What are the manipulations that are performed over here? Also is this done in SSIS package ? If so what is the control and data flow here?Happy to help! Thanks. Regards and good Wishes, Deepak.
Free Windows Admin Tool Kit Click here and download it now
August 20th, 2011 10:02am

What is the data type of the NmrGrupy column? If it is a varchar, SQL Server might be trying to do an implicit cast.John Welch | www.varigence.com | www.agilebi.com | ssisUnit.codeplex.com
August 20th, 2011 10:59am

rozlicz is a view from table dbo.Tematy and a view dbo.Konta: SELECT TOP (100) PERCENT YEAR(dbo.Konta.datod) AS ROK, SUM(dbo.Konta.obr_nar_wn) AS obroty, dbo.Tematy.NmrGrupy, dbo.Tematy.NmrTematu, SUBSTRING(dbo.Konta.konto_idm, 13, 3) AS NmrZak FROM dbo.Tematy INNER JOIN dbo.Konta ON dbo.Tematy.NmrGrupy = SUBSTRING(dbo.Konta.konto_idm, 5, 2) AND dbo.Tematy.NmrTematu = SUBSTRING(dbo.Konta.konto_idm, 8, 4) WHERE (MONTH(dbo.Konta.datod) = '12') AND (SUBSTRING(dbo.Konta.konto_idm, 17, 3) <> '726') AND (DAY(dbo.Konta.datod) = '1') GROUP BY YEAR(dbo.Konta.datod), dbo.Tematy.NmrGrupy, dbo.Tematy.NmrTematu, SUBSTRING(dbo.Konta.konto_idm, 13, 3) ORDER BY ROK, dbo.Tematy.NmrGrupy, dbo.Tematy.NmrTematu, NmrZak dbo.Tematy.NmrGrupy is an INT data type but its joined with a part of string dbo.Konta.konto_idm btw. similar problem occurs when trying set condition on NmrTemat but there is '1-00' instead of 10 strange thing is that it affects only few numbers especially '10' one more info it started when i moved from sql 2000 to 2008
Free Windows Admin Tool Kit Click here and download it now
August 20th, 2011 11:40am

In your view, you need to cast the result of the SUBSTRING in your join to an INT: FROM dbo.Tematy INNER JOIN dbo.Konta ON dbo.Tematy.NmrGrupy = CAST(SUBSTRING(dbo.Konta.konto_idm, 5, 2) AS INT) AND dbo.Tematy.NmrTematu = CAST(SUBSTRING(dbo.Konta.konto_idm, 8, 4) AS INT) You may also need to change the substring logic a bit - it looks like it's picking up a trailing dash. In SQL 2000, it may have been a little more lenient in the implicit data conversion, and supported converting the trailing dash without error. It looks like 2008 isn't allowing that. John Welch | www.varigence.com | www.agilebi.com | ssisUnit.codeplex.com
August 20th, 2011 12:23pm

I've been wrong The problem was not '10' but NmrGrupy FROM dbo.Tematy INNER JOIN dbo.Konta ON CAST(dbo.Tematy.NmrGrupy AS INT) = SUBSTRING(dbo.Konta.konto_idm, 5, 2) AND CAST(dbo.Tematy.NmrTematu AS INT) = SUBSTRING(dbo.Konta.konto_idm, 8, 4) did the job or in SELECT WHERE CAST(NmrGrupy AS INT) = 10 think we could close this thread thanks for help
Free Windows Admin Tool Kit Click here and download it now
August 20th, 2011 1:04pm

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics