Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

PROD ISSUE : Conversion failed when converting the varchar value 'DT-1205-006049' to data type int. Expand / Collapse
Author
Message
Posted Thursday, September 13, 2012 11:02 AM
SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Wednesday, February 13, 2013 7:48 AM
Points: 28, Visits: 193
The issue is that the query runs in test and doesnt run in prod.

We have 2 fields in my example: field 1 and field 2

an example if rows:
table 1
field1 field2
11 BX-00006767
12 BX-00006767
13 BX-00006767
14 BX-00006767
DT-1205-006049 BX-00006768

The query is :
Select CAST(RIGHT(field1, LEN(field1)-1) AS INT)
from table1
where field2 = BX-00006767

On Prod we get the error we get is "Conversion failed when converting the varchar value 'DT-1205-006049' to data type int."

I believe that since that value is not in the result set due to a WHERE statement, it is evaluating the CASE first rather than the WHERE on prod.
In DEV this runs fine with a refresh of DEV a day ago. Both have the same data in the table.
The showpan for both are different. so it appears to be an order of operations thing.
I can post the showplan but I don't think it is relevant to the question below.

The question is, without changing my code is there any way I can force the same plan that is on DEV to run in prod?

Thanks!


Michael B
Data Architect
MCT, MCITP(SQL DBA 2005/2008),MCTS, MCP,MCDBA
Post #1358720
Posted Thursday, September 13, 2012 11:18 AM


SSCoach

SSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoach

Group: General Forum Members
Last Login: Monday, June 17, 2013 1:45 PM
Points: 15,442, Visits: 9,572
Where I've run into that kind of thing, I usually have the script/proc insert the rows I want to work on into a temp table, then run the string manipulation on the temp table. Is that an option for you in this case?

- Gus "GSquared", RSVP, OODA, MAP, NMVP, FAQ, SAT, SQL, DNA, RNA, UOI, IOU, AM, PM, AD, BC, BCE, USA, UN, CF, ROFL, LOL, ETC
Property of The Thread

"Nobody knows the age of the human race, but everyone agrees it's old enough to know better." - Anon
Post #1358726
Posted Thursday, September 13, 2012 11:21 AM
SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Wednesday, February 13, 2013 7:48 AM
Points: 28, Visits: 193
That was my suggestion to the developer. they have now created an emergency change in change control to get it done. now its not as urgent butmy curiousity is till there. can I move a query plan from one server to another using forced plan without adding anything to the query:)

Michael B
Data Architect
MCT, MCITP(SQL DBA 2005/2008),MCTS, MCP,MCDBA
Post #1358729
Posted Friday, September 14, 2012 6:11 AM


SSCoach

SSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoach

Group: General Forum Members
Last Login: Monday, June 17, 2013 1:45 PM
Points: 15,442, Visits: 9,572
Nope. You'd have to at least add the plan to the query. And even that's not guaranteed to work.

- Gus "GSquared", RSVP, OODA, MAP, NMVP, FAQ, SAT, SQL, DNA, RNA, UOI, IOU, AM, PM, AD, BC, BCE, USA, UN, CF, ROFL, LOL, ETC
Property of The Thread

"Nobody knows the age of the human race, but everyone agrees it's old enough to know better." - Anon
Post #1359206
Posted Friday, September 14, 2012 6:13 AM
SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Wednesday, February 13, 2013 7:48 AM
Points: 28, Visits: 193
thought so. thanks all!

Michael B
Data Architect
MCT, MCITP(SQL DBA 2005/2008),MCTS, MCP,MCDBA
Post #1359208
Posted Monday, September 17, 2012 2:27 PM
SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Wednesday, February 13, 2013 7:48 AM
Points: 28, Visits: 193
OK. here is what we have found.
.....the prod db there is little activity IO wise...


sorry. I mis-posted this. this was supposed to go to a different thread.. sorry (http://www.sqlservercentral.com/Forums/Topic1349180-1550-4.aspx?Update=1)


Michael B
Data Architect
MCT, MCITP(SQL DBA 2005/2008),MCTS, MCP,MCDBA
Post #1360443
Posted Monday, September 17, 2012 2:52 PM


SSC-Insane

SSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-Insane

Group: General Forum Members
Last Login: Yesterday @ 11:14 PM
Points: 21,832, Visits: 27,862
I don't know since the following runs with no problems for me:


create table dbo.table1 (
Field1 varchar(30),
Field2 varchar(30));
go

insert into dbo.table1
values
('11','BX-00006767'),
('12','BX-00006767'),
('13','BX-00006767'),
('14','BX-00006767'),
('DT-1205-006049','BX-00006768');
go
select Field1, Field2 from dbo.table1;
go
select cast(right(Field1,len(field1)-1) as int)
from dbo.table1
where Field2 = 'BX-00006767';
go
drop table dbo.table1;
go


All I can think of is that we aren't getting the full story. Something else is going on and we just don't see it.



Lynn Pettis

For better assistance in answering your questions, click here
For tips to get better help with Performance Problems, click here
For Running Totals and its variations, click here or when working with partitioned tables
For more about Tally Tables, click here
For more about Cross Tabs and Pivots, click here and here
Managing Transaction Logs

SQL Musings from the Desert Fountain Valley SQL (My Mirror Blog)
Post #1360460
Posted Tuesday, September 18, 2012 4:14 AM
Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Today @ 1:40 AM
Points: 1,272, Visits: 4,310
Is that query in the OP transcribed correctly? Because you don't seem to have enclosed the BX-00006767 value in quotes, which means SQL server isn't going to interpret it as a string...although I would expect that to fail on both machines, to be honest.
Post #1360660
Posted Tuesday, September 18, 2012 5:57 AM


SSC-Insane

SSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-Insane

Group: General Forum Members
Last Login: Yesterday @ 11:14 PM
Points: 21,832, Visits: 27,862
paul.knibbs (9/18/2012)
Is that query in the OP transcribed correctly? Because you don't seem to have enclosed the BX-00006767 value in quotes, which means SQL server isn't going to interpret it as a string...although I would expect that to fail on both machines, to be honest.


Agree, OP did not provide DDL for the table, but based on what was posted, the data types had to varchar (possibly nvarchar). To insert the data provided this meant that the values had to surrounded in single quotes. It also meant the query posted by the OP was incorrect in its WHERE clause as the character value was not surrounded by single quotes unless that value was supposed to be a column name, which is not supported by what the OP posted.



Lynn Pettis

For better assistance in answering your questions, click here
For tips to get better help with Performance Problems, click here
For Running Totals and its variations, click here or when working with partitioned tables
For more about Tally Tables, click here
For more about Cross Tabs and Pivots, click here and here
Managing Transaction Logs

SQL Musings from the Desert Fountain Valley SQL (My Mirror Blog)
Post #1360716
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse